Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove documentation about setuptools integration Refs #5534 Fixes #3814 #5546

Merged
merged 1 commit into from Jul 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
97 changes: 0 additions & 97 deletions doc/en/goodpractices.rst
Expand Up @@ -219,101 +219,4 @@ against your source code checkout, helping to detect packaging
glitches.


Integrating with setuptools / ``python setup.py test`` / ``pytest-runner``
nicoddemus marked this conversation as resolved.
Show resolved Hide resolved
--------------------------------------------------------------------------

You can integrate test runs into your setuptools based project
with the `pytest-runner <https://pypi.org/project/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