Skip to content

Commit eefc9d4

Browse files
authored
[DOCS] Clarify tmp_path directory location and retention (#11830)
Fixes #11789 and #11790
1 parent 7fd561e commit eefc9d4

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ Evgeny Seliverstov
141141
Fabian Sturm
142142
Fabien Zarifian
143143
Fabio Zadrozny
144+
faph
144145
Felix Hofstätter
145146
Felix Nieuwenhuizen
146147
Feng Ma

changelog/11790.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Documented the retention of temporary directories created using the ``tmp_path`` fixture in more detail.

doc/en/how-to/tmp_path.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ How to use temporary directories and files in tests
88
The ``tmp_path`` fixture
99
------------------------
1010

11-
You can use the ``tmp_path`` fixture which will
12-
provide a temporary directory unique to the current test,
13-
created in the `base temporary directory`_.
11+
You can use the ``tmp_path`` fixture which will provide a temporary directory
12+
unique to each test function.
1413

1514
``tmp_path`` is a :class:`pathlib.Path` object. Here is an example test usage:
1615

@@ -62,6 +61,11 @@ Running this would result in a passed test except for the last
6261
FAILED test_tmp_path.py::test_create_file - assert 0
6362
============================ 1 failed in 0.12s =============================
6463
64+
By default, ``pytest`` retains the temporary directory for the last 3 ``pytest``
65+
invocations. Concurrent invocations of the same test function are supported by
66+
configuring the base temporary directory to be unique for each concurrent
67+
run. See `temporary directory location and retention`_ for details.
68+
6569
.. _`tmp_path_factory example`:
6670

6771
The ``tmp_path_factory`` fixture
@@ -100,7 +104,7 @@ See :ref:`tmp_path_factory API <tmp_path_factory factory api>` for details.
100104
.. _tmpdir:
101105

102106
The ``tmpdir`` and ``tmpdir_factory`` fixtures
103-
---------------------------------------------------
107+
----------------------------------------------
104108

105109
The ``tmpdir`` and ``tmpdir_factory`` fixtures are similar to ``tmp_path``
106110
and ``tmp_path_factory``, but use/return legacy `py.path.local`_ objects
@@ -124,10 +128,10 @@ See :fixture:`tmpdir <tmpdir>` :fixture:`tmpdir_factory <tmpdir_factory>`
124128
API for details.
125129

126130

127-
.. _`base temporary directory`:
131+
.. _`temporary directory location and retention`:
128132

129-
The default base temporary directory
130-
-----------------------------------------------
133+
Temporary directory location and retention
134+
------------------------------------------
131135

132136
Temporary directories are by default created as sub-directories of
133137
the system temporary directory. The base name will be ``pytest-NUM`` where
@@ -152,7 +156,7 @@ You can override the default temporary directory setting like this:
152156
for that purpose only.
153157

154158
When distributing tests on the local machine using ``pytest-xdist``, care is taken to
155-
automatically configure a basetemp directory for the sub processes such that all temporary
156-
data lands below a single per-test run basetemp directory.
159+
automatically configure a `basetemp` directory for the sub processes such that all temporary
160+
data lands below a single per-test run temporary directory.
157161

158162
.. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html

src/_pytest/legacypath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ def tmpdir(tmp_path: Path) -> LEGACY_PATH:
326326
327327
By default, a new base temporary directory is created each test session,
328328
and old bases are removed after 3 sessions, to aid in debugging. If
329-
``--basetemp`` is used then it is cleared each session. See :ref:`base
330-
temporary directory`.
329+
``--basetemp`` is used then it is cleared each session. See
330+
:ref:`temporary directory location and retention`.
331331
332332
The returned object is a `legacy_path`_ object.
333333

src/_pytest/tmpdir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ def tmp_path(
262262
and old bases are removed after 3 sessions, to aid in debugging.
263263
This behavior can be configured with :confval:`tmp_path_retention_count` and
264264
:confval:`tmp_path_retention_policy`.
265-
If ``--basetemp`` is used then it is cleared each session. See :ref:`base
266-
temporary directory`.
265+
If ``--basetemp`` is used then it is cleared each session. See
266+
:ref:`temporary directory location and retention`.
267267
268268
The returned object is a :class:`pathlib.Path` object.
269269
"""

0 commit comments

Comments
 (0)