@@ -219,101 +219,4 @@ against your source code checkout, helping to detect packaging
219219glitches.
220220
221221
222- Integrating with setuptools / ``python setup.py test `` / ``pytest-runner ``
223- --------------------------------------------------------------------------
224-
225- You can integrate test runs into your setuptools based project
226- with the `pytest-runner <https://pypi.org/project/pytest-runner/ >`_ plugin.
227-
228- Add this to ``setup.py `` file:
229-
230- .. code-block :: python
231-
232- from setuptools import setup
233-
234- setup(
235- # ...,
236- setup_requires = [" pytest-runner" , ... ],
237- tests_require = [" pytest" , ... ],
238- # ...,
239- )
240-
241-
242- And create an alias into ``setup.cfg `` file:
243-
244-
245- .. code-block :: ini
246-
247- [aliases]
248- test =pytest
249-
250- If you now type::
251-
252- python setup.py test
253-
254- this will execute your tests using ``pytest-runner ``. As this is a
255- standalone version of ``pytest `` no prior installation whatsoever is
256- required for calling the test command. You can also pass additional
257- arguments to pytest such as your test directory or other
258- options using ``--addopts ``.
259-
260- You can also specify other pytest-ini options in your ``setup.cfg `` file
261- by putting them into a ``[tool:pytest] `` section:
262-
263- .. code-block :: ini
264-
265- [tool:pytest]
266- addopts = --verbose
267- python_files = testing/*/*.py
268-
269-
270- Manual Integration
271- ^^^^^^^^^^^^^^^^^^
272-
273- If for some reason you don't want/can't use ``pytest-runner ``, you can write
274- your own setuptools Test command for invoking pytest.
275-
276- .. code-block :: python
277-
278- import sys
279-
280- from setuptools.command.test import test as TestCommand
281-
282-
283- class PyTest (TestCommand ):
284- user_options = [(" pytest-args=" , " a" , " Arguments to pass to pytest" )]
285-
286- def initialize_options (self ):
287- TestCommand.initialize_options(self )
288- self .pytest_args = " "
289-
290- def run_tests (self ):
291- import shlex
292-
293- # import here, cause outside the eggs aren't loaded
294- import pytest
295-
296- errno = pytest.main(shlex.split(self .pytest_args))
297- sys.exit(errno)
298-
299-
300- setup(
301- # ...,
302- tests_require = [" pytest" ],
303- cmdclass = {" pytest" : PyTest},
304- )
305-
306- Now if you run::
307-
308- python setup.py test
309-
310- this will download ``pytest `` if needed and then run your tests
311- as you would expect it to. You can pass a single string of arguments
312- using the ``--pytest-args `` or ``-a `` command-line option. For example::
313-
314- python setup.py test -a "--durations=5"
315-
316- is equivalent to running ``pytest --durations=5 ``.
317-
318-
319222.. include :: links.inc
0 commit comments