问题描述
我有一个带有 setup.py
文件的项目.我使用 pytest
作为测试框架,并且还在我的代码上运行各种 linter(pep8
、pylint
、pydocstyle
、pyflakes
等).我使用 tox
在多个 Python 版本中运行它们,并使用 Sphinx
构建文档.
I have a project with a setup.py
file. I use pytest
as the testing framework and I also run various linters on my code (pep8
, pylint
, pydocstyle
, pyflakes
, etc). I use tox
to run these in several Python versions, as well as build documentation using Sphinx
.
我想使用 python setup.py test
任务在我的源代码上运行我的测试套件以及 linters.如果我实现了这一点,那么我将只使用 python setup.py test
作为在我的 tox.ini
文件中运行测试的命令.
I would like to run my test suites as well as the linters on my source code with the python setup.py test
task. If I acheive this, I will then just use python setup.py test
as the command for running tests in my tox.ini
file.
所以我的问题是:
- 使用
python setup.py test
执行这些操作是否合理/好的做法?或者我应该为此使用其他工具,例如直接在tox
中编写这些命令? - 如何让
setup.py
在test
任务中执行这些操作?
- Is it reasonable / good practice to do these actions with
python setup.py test
? Or should I just use some other tool for that, like writing those command directly intox
? - How do I get
setup.py
to do these actions in thetest
task?
我知道 py.test
有关于 setup.py test
的集成说明(这里:http://pytest.org/latest/goodpractices.html#integrating-with-setuptools-python-setup-py-test-pytest-runner),但我正在寻找更任意 CLI 命令"的路线,因为我想运行多个工具.
I know py.test
has integration instructions for setup.py test
(here: http://pytest.org/latest/goodpractices.html#integrating-with-setuptools-python-setup-py-test-pytest-runner), but I'm looking for a more "arbitrary CLI commands" route, since I want to run several tools.
推荐答案
1. 我个人更喜欢 tox 来完成这些任务,因为
1. I personally prefer tox for these tasks, because
- 它还会检查您的 deps 是否正确安装(在所有 py 版本上)
- 它可以使用多个 python 版本 (virtualenv) 测试您的代码
对于您的设置(因为您已经在使用 tox),我并没有真正看到将 python setup.py test
而不是确切的测试命令写入您的 的好处tox.ini
,因为它只会增加一些复杂性(新用户/贡献者必须搜索两个文件(tox.ini
和 setup.py
)运行的测试/工具而不是一个 (tox.ini
).
And with your setup (since you're already using tox) i don't really see the benefits of writing python setup.py test
instead of the exact test-commands into your tox.ini
, because it will just add some more complexitiy (new users/contributors have to search two files (tox.ini
and setup.py
) for tests/tools running instead of one (tox.ini
).
2.
要使用此命令,您项目的测试必须包含在单元测试中由函数、TestCase 类或方法或模块组成的测试套件或包含 TestCase 类的包.
这篇关于如何在`python setup.py test`中运行py.test和linters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!