如何在`python setup.py test`中运行py.test和linters [英] How to run py.test and linters in `python setup.py test`

查看:57
本文介绍了如何在`python setup.py test`中运行py.test和linters的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 setup.py 文件的项目.我使用 pytest 作为测试框架,并且还在我的代码上运行各种 linter(pep8pylintpydocstylepyflakes 等).我使用 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.

所以我的问题是:

  1. 使用 python setup.py test 执行这些操作是否合理/好的做法?或者我应该为此使用其他工具,例如直接在 tox 中编写这些命令?
  2. 如何让 setup.pytest 任务中执行这些操作?
  1. 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 in tox?
  2. How do I get setup.py to do these actions in the test 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.inisetup.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 类的包.

To use this command, your project’s tests must be wrapped in a unittest test suite by either a function, a TestCase class or method, or a module or package containing TestCase classes.

setuptools#test

这篇关于如何在`python setup.py test`中运行py.test和linters的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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