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

Document usage of Pytest with Tox as a FAQ entry #3192

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions docs/changelog/3187.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Documented usage of ``pytest`` with ``tox run-parallel`` - by :user:`faph`.
45 changes: 45 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,48 @@ If you need to test against e.g. Python 2.7, 3.5 or 3.6, you need to add the fol

In case you need to do this for many repositories, we recommend to use
`all-repos <https://github.com/asottile/all-repos>`_.


Testing with Pytest
-------------------

Running ``pytest`` from ``tox`` can be configured like this:

.. code-block:: ini

[tox]
envlist = py311, py312

[testenv]
commands = pytest

If required, ``tox`` positional arguments can be passed through to ``pytest``:

.. code-block:: ini

[testenv]
commands = pytest {posargs}

When running ``tox`` in parallel mode (:ref:`tox-run-parallel-(p)`), care should be taken to ensure concurrent
``pytest`` invocations are fully isolated.

This can be achieved by setting ``pytest``'s base temporary directory to a unique temporary directory for each virtual
environment as provided by ``tox``:

.. code-block:: ini

[testenv]
commands = pytest --basetemp="{env_tmp_dir}"

Setting the ``pytest`` ``--basetemp`` argument also causes all temporary ``pytest`` files to be deleted immediately
after the tests are completed. To restore the default ``pytest`` behavior to retain temporary files for the most recent
``pytest`` invocations, the system's temporary directory location could be configured like this instead:

.. code-block:: ini

[tox]
setenv =
faph marked this conversation as resolved.
Show resolved Hide resolved
TEMP = {env_tmp_dir}

[testenv]
commands = pytest