如何在 PyTest 和 PyQt5 中使用 python3 setup.py 测试? [英] How to use python3 setup.py test with PyTest and PyQt5?

查看:73
本文介绍了如何在 PyTest 和 PyQt5 中使用 python3 setup.py 测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像这里一样遵循良好的集成http://pytest.org/latest/goodpractices.html 在依赖 PyQt5 的包中?(我用的是 Ubuntu 14.04,不知道有没有影响)

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')

我可以pip3 install pyqt5,这就是为什么我将pyqt5放在我的setup.py中.在命令行中运行 py.test 也可以.

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.

推荐答案

在命令行中运行 py.test 会在您当前的 Python 环境中执行测试.

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

运行 python3 setup.py test(根据 pytest 的良好集成实践"使用 pytest-runner)创建一个伪虚拟环境.它将任何缺失的依赖项作为鸡蛋提取(将它们存储在 .eggs 目录中),然后在上述环境中执行测试.

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.

明确地说,py.testpython3 setup.py test 做不同的事情.

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 - 启动 pytest,您的测试可能会失败,因为 PyQt5 不可导入
  • pip3 安装 PyQt5 &&py.test - 在当前环境中安装 PyQt5 的 bdist_wheel 然后启动 pytest,你的测试大概会成功
  • 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
  • python3 setup.py test - 启动 pytest-runner,检查 setup.py 中的依赖项,确定 PyQt5 不可用,尝试拉入鸡蛋(但不能,因为 PyQt5 仅可用作 bdist_wheel,而不是源分发),然后吐出错误消息并退出
  • pip3 安装 PyQt5 &&python3 setup.py test - 在当前环境下安装 PyQt5 的 bdist_wheel 然后启动 pytest-runner,检查 setup.py 中的依赖项,确定所有依赖项都可用,启动 pytest,然后你的测试大概会成功
  • 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

简单的答案是否定的,不可能做到您所要求的.无论如何,您需要在运行测试之前将 PyQt5 安装到环境中.

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.

这篇关于如何在 PyTest 和 PyQt5 中使用 python3 setup.py 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆