Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/791.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document the ``pytest_xdist_auto_num_workers`` hook.
18 changes: 15 additions & 3 deletions docs/distribution.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ Running tests across multiple CPUs

To send tests to multiple CPUs, use the ``-n`` (or ``--numprocesses``) option::

pytest -n 8
pytest -n auto

Pass ``-n auto`` to use as many processes as your computer has CPU cores. This
can lead to considerable speed ups, especially if your test suite takes a
This can lead to considerable speed ups, especially if your test suite takes a
noticeable amount of time.

With ``-n auto``, pytest-xdist will use as many processes as your computer
has CPU cores.
Pass a number, e.g. ``-n 8``, to specify the number of processes explicitly.

To specify a different meaning for ``-n auto`` for your tests,
you can implement the ``pytest_xdist_auto_num_workers``
`pytest hook <https://docs.pytest.org/en/latest/how-to/writing_plugins.html>`__
(a function named ``pytest_xdist_auto_num_workers`` in e.g. ``conftest.py``)
that returns the number of processes to use.


Parallelization can be configured further with these options:

* ``--maxprocesses=maxprocesses``: limit the maximum number of workers to
process the tests.

Expand Down