我正在使用 GitHub 操作构建持续集成工作流。此工作流将用于运行单元测试和测试构建状态。该工作流将由许多开发了 python 包的不同人员使用,因此我试图使其尽可能通用和模块化。我的目标是将运行单元测试和测试这些包的构建状态的任务分开,这引出了我的问题,python setup.py test
和 命令之间有什么区别pytest {package}
?
具体而言,
使用
pytest {package}
命令运行单元测试是否会自动构建您的包,或者如果不构建您的包就无法运行单元测试?我知道 setup.py 是 setuptools 的构建脚本,我已经阅读了命令
python setup.py test
的作用,它说它将:在 -放置构建。那么这个命令是不是默认使用pytest呢?
我还在 setuptools 文档中看到了构建命令,所以为了回答我自己的问题,我会做 pytest {package}
只运行单元测试和 python setup .py build
测试包的构建状态。
这样对吗?
非常感谢。
最佳答案
Does running unit tests with the command pytest {package} automatically build your package?
不,它不需要,您不需要它 - 您不需要该包来运行您的测试。
Is it not possible to run unit tests without building your package?
这是可能的。
I know that setup.py is the build script for setuptools and I have read what the command
python setup.py test
does and it says it will: run unit tests after in-place build. So does this command use pytest by default then?
它确实会运行配置的测试,因此这取决于您的设置。如前所述,运行 python setup.py test
已被弃用,因此您通常不必担心这一点 - 直接在 CI 环境中使用 pytest
。请注意,尽管某些 Linux 发行版在部署时仍会默认运行此程序,因此如果您想分发您的软件包,您可能仍需要对其进行测试。
要通过 setup
运行 pytest
你可能需要在你的 setup.py
中有这样的东西:
setup(
packages=find_packages(),
tests_require=['pytest'],
)
关于python - "python setup.py test"与 "pytest {package}"之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60743622/