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
.
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.
So my questions are:
python setup.py test
? Or should I just use some other tool for that, like writing those command directly in tox
?setup.py
to do these actions in the test
task?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.
You can just specify test_suite="tests", and it will pick up everything recursively. Note that each nested directory will need to have an __init__.py file in it. You need to do from setuptools import setup instead of from distutils. core import setup for this option to exist.
Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .
Linters are programs that advise about code quality by displaying warnings and errors. They can detect your Python code mistakes, notice invalid code patterns and find elements that do not follow your conventions. Python linters have a number of advantages, such as: Preventing bugs in a project.
1. I personally prefer tox for these tasks, because
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With