diff --git a/doc/en/goodpractices.rst b/doc/en/goodpractices.rst index 2314c00660b..9622cc766fd 100644 --- a/doc/en/goodpractices.rst +++ b/doc/en/goodpractices.rst @@ -219,101 +219,4 @@ against your source code checkout, helping to detect packaging glitches. -Integrating with setuptools / ``python setup.py test`` / ``pytest-runner`` --------------------------------------------------------------------------- - -You can integrate test runs into your setuptools based project -with the `pytest-runner `_ plugin. - -Add this to ``setup.py`` file: - -.. code-block:: python - - from setuptools import setup - - setup( - # ..., - setup_requires=["pytest-runner", ...], - tests_require=["pytest", ...], - # ..., - ) - - -And create an alias into ``setup.cfg`` file: - - -.. code-block:: ini - - [aliases] - test=pytest - -If you now type:: - - python setup.py test - -this will execute your tests using ``pytest-runner``. As this is a -standalone version of ``pytest`` no prior installation whatsoever is -required for calling the test command. You can also pass additional -arguments to pytest such as your test directory or other -options using ``--addopts``. - -You can also specify other pytest-ini options in your ``setup.cfg`` file -by putting them into a ``[tool:pytest]`` section: - -.. code-block:: ini - - [tool:pytest] - addopts = --verbose - python_files = testing/*/*.py - - -Manual Integration -^^^^^^^^^^^^^^^^^^ - -If for some reason you don't want/can't use ``pytest-runner``, you can write -your own setuptools Test command for invoking pytest. - -.. code-block:: python - - import sys - - from setuptools.command.test import test as TestCommand - - - class PyTest(TestCommand): - user_options = [("pytest-args=", "a", "Arguments to pass to pytest")] - - def initialize_options(self): - TestCommand.initialize_options(self) - self.pytest_args = "" - - def run_tests(self): - import shlex - - # import here, cause outside the eggs aren't loaded - import pytest - - errno = pytest.main(shlex.split(self.pytest_args)) - sys.exit(errno) - - - setup( - # ..., - tests_require=["pytest"], - cmdclass={"pytest": PyTest}, - ) - -Now if you run:: - - python setup.py test - -this will download ``pytest`` if needed and then run your tests -as you would expect it to. You can pass a single string of arguments -using the ``--pytest-args`` or ``-a`` command-line option. For example:: - - python setup.py test -a "--durations=5" - -is equivalent to running ``pytest --durations=5``. - - .. include:: links.inc