@@ -8,9 +8,8 @@ How to use temporary directories and files in tests
8
8
The ``tmp_path `` fixture
9
9
------------------------
10
10
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.
14
13
15
14
``tmp_path `` is a :class: `pathlib.Path ` object. Here is an example test usage:
16
15
@@ -62,6 +61,11 @@ Running this would result in a passed test except for the last
62
61
FAILED test_tmp_path.py::test_create_file - assert 0
63
62
============================ 1 failed in 0.12s =============================
64
63
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
+
65
69
.. _`tmp_path_factory example` :
66
70
67
71
The ``tmp_path_factory `` fixture
@@ -100,7 +104,7 @@ See :ref:`tmp_path_factory API <tmp_path_factory factory api>` for details.
100
104
.. _tmpdir :
101
105
102
106
The ``tmpdir `` and ``tmpdir_factory `` fixtures
103
- ---------------------------------------------------
107
+ ----------------------------------------------
104
108
105
109
The ``tmpdir `` and ``tmpdir_factory `` fixtures are similar to ``tmp_path ``
106
110
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>`
124
128
API for details.
125
129
126
130
127
- .. _`base temporary directory` :
131
+ .. _`temporary directory location and retention ` :
128
132
129
- The default base temporary directory
130
- -----------------------------------------------
133
+ Temporary directory location and retention
134
+ ------------------------------------------
131
135
132
136
Temporary directories are by default created as sub-directories of
133
137
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:
152
156
for that purpose only.
153
157
154
158
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.
157
161
158
162
.. _`py.path.local` : https://py.readthedocs.io/en/latest/path.html
0 commit comments