Skip to content

Commit 5054a86

Browse files
authored
Document usage of Pytest with Tox as a FAQ entry (#3192)
1 parent 8eaf09f commit 5054a86

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

docs/changelog/3187.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Documented usage of ``pytest`` with ``tox run-parallel`` - by :user:`faph`.

docs/faq.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
366366
367367
In case you need to do this for many repositories, we recommend to use
368368
`all-repos <https://github.com/asottile/all-repos>`_.
369+
370+
371+
Testing with Pytest
372+
-------------------
373+
374+
Running ``pytest`` from ``tox`` can be configured like this:
375+
376+
.. code-block:: ini
377+
378+
[tox]
379+
envlist = py311, py312
380+
381+
[testenv]
382+
commands = pytest
383+
384+
If required, ``tox`` positional arguments can be passed through to ``pytest``:
385+
386+
.. code-block:: ini
387+
388+
[testenv]
389+
commands = pytest {posargs}
390+
391+
When running ``tox`` in parallel mode (:ref:`tox-run-parallel-(p)`), care should be taken to ensure concurrent
392+
``pytest`` invocations are fully isolated.
393+
394+
This can be achieved by setting ``pytest``'s base temporary directory to a unique temporary directory for each virtual
395+
environment as provided by ``tox``:
396+
397+
.. code-block:: ini
398+
399+
[testenv]
400+
commands = pytest --basetemp="{env_tmp_dir}"
401+
402+
Setting the ``pytest`` ``--basetemp`` argument also causes all temporary ``pytest`` files to be deleted immediately
403+
after the tests are completed. To restore the default ``pytest`` behavior to retain temporary files for the most recent
404+
``pytest`` invocations, the system's temporary directory location could be configured like this instead:
405+
406+
.. code-block:: ini
407+
408+
[tox]
409+
set_env =
410+
TEMP = {env_tmp_dir}
411+
412+
[testenv]
413+
commands = pytest

0 commit comments

Comments
 (0)