How to use python3 setup.py test with PyTest and PyQt5?

扶醉桌前 提交于 2019-12-25 17:36:30

问题


Is it possible to follow Good Integration as here http://pytest.org/latest/goodpractices.html in a package that depends on PyQt5 ? (I am using Ubuntu 14.04, don't know if this impacts)

I get the following with both suggested approaches:

$ python3 setup.py test
running test
Searching for pyqt5
Reading https://pypi.python.org/simple/pyqt5/
No local packages or download links found for pyqt5
error: Could not find suitable distribution for Requirement.parse('pyqt5')

I can pip3 install pyqt5, which is why I place pyqt5 in my setup.py. Also running py.test in the command line just works.


回答1:


Running py.test in the command line performs the tests in your current Python environment.

Running python3 setup.py test (with pytest-runner in accordance with pytest's 'Good Integration Practices') creates a pseudo-virtualenv. It pulls in any missing dependencies as eggs (storing them in .eggs directory), then performs the test in the aforementioned environment.

To be clear, py.test and python3 setup.py test do different things.


To illustrate the difference between these two commands, here are a few scenarios:

py.test

  • py.test - launches pytest, your tests presumably fail because PyQt5 is not importable
  • pip3 install PyQt5 && py.test - install bdist_wheel of PyQt5 in the current environment then launches pytest, your tests presumably succeed

pytest-runner

  • python3 setup.py test - launch pytest-runner, checks dependencies in setup.py, determines that PyQt5 is not available, attempts to pull in an egg (but is unable to as PyQt5 is only available as a bdist_wheel, not a source distribution), then spits out an error message and exits
  • pip3 install PyQt5 && python3 setup.py test - install bdist_wheel of PyQt5 in the current environment then launches pytest-runner, checks dependencies in setup.py, determines that all dependencies are available, launches pytest, and your tests presumably succeed

The simple answer is no, it's not possible to do what you're asking. One way or another, you need to install PyQt5 into the environment prior to running tests.



来源:https://stackoverflow.com/questions/38243437/how-to-use-python3-setup-py-test-with-pytest-and-pyqt5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!