I Want To Make My Pytest Unittests Run With The "python Setup.py Test" Command
In the default behaviour giving the command python setup.py test will execute the unit tests associated with a module. This default behaviour can be made to work simply by providin
Solution 1:
I personally have not done this. But I'd recommend checking out some legit python projects on github to see how they have done this. E.g. requests:
#!/usr/bin/env pythonimport sys
from setuptools import setup
from setuptools.command.test import test as TestCommand
classPyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass into py.test")]
definitialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
deffinalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = Truedefrun_tests(self):
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
setup(
# pass all the required/desired args
cmdclass={'test': PyTest}
)
You can even pass args to pytest runner python setup.py test --pytest-args='-vvv'
Also checkout the docs: https://docs.pytest.org/en/latest/goodpractices.html#integrating-with-setuptools-python-setup-py-test-pytest-runner (thanks to @jonrsharpe for the link)
Post a Comment for "I Want To Make My Pytest Unittests Run With The "python Setup.py Test" Command"