@@ -133,27 +133,47 @@ API for details.
133133Temporary directory location and retention
134134------------------------------------------
135135
136- Temporary directories are by default created as sub-directories of
137- the system temporary directory. The base name will be ``pytest-NUM `` where
138- ``NUM `` will be incremented with each test run.
139- By default, entries older than 3 temporary directories will be removed.
140- This behavior can be configured with :confval: `tmp_path_retention_count ` and
141- :confval: `tmp_path_retention_policy `.
136+ The temporary directories,
137+ as returned by the :fixture: `tmp_path ` and (now deprecated) :fixture: `tmpdir ` fixtures,
138+ are automatically created under a base temporary directory,
139+ in a structure that depends on the ``--basetemp `` option:
142140
143- Using the ``--basetemp ``
144- option will remove the directory before every run, effectively meaning the temporary directories
145- of only the most recent run will be kept.
141+ - By default (when the ``--basetemp `` option is not set),
142+ the temporary directories will follow this template:
146143
147- You can override the default temporary directory setting like this:
144+ .. code-block :: text
148145
149- .. code-block :: bash
146+ {temproot}/pytest-of-{user}/pytest-{num}/{testname}/
150147
151- pytest --basetemp=mydir
148+ where:
152149
153- .. warning ::
150+ - ``{temproot} `` is the system temporary directory
151+ as determined by :py:func: `tempfile.gettempdir `.
152+ It can be overridden by the :envvar: `PYTEST_DEBUG_TEMPROOT ` environment variable.
153+ - ``{user} `` is the user name running the tests,
154+ - ``{num} `` is a number that is incremented with each test suite run
155+ - ``{testname} `` is a sanitized version of :py:attr: `the name of the current test <_pytest.nodes.Node.name> `.
154156
155- The contents of ``mydir `` will be completely removed, so make sure to use a directory
156- for that purpose only.
157+ The auto-incrementing ``{num} `` placeholder provides a basic retention feature
158+ and avoids that existing results of previous test runs are blindly removed.
159+ By default, the last 3 temporary directories are kept,
160+ but this behavior can be configured with
161+ :confval: `tmp_path_retention_count ` and :confval: `tmp_path_retention_policy `.
162+
163+ - When the ``--basetemp `` option is used (e.g. ``pytest --basetemp=mydir ``),
164+ it will be used directly as base temporary directory:
165+
166+ .. code-block :: text
167+
168+ {basetemp}/{testname}/
169+
170+ Note that there is no retention feature in this case:
171+ only the results of the most recent run will be kept.
172+
173+ .. warning ::
174+
175+ The directory given to ``--basetemp `` will be cleared blindly before each test run,
176+ so make sure to use a directory for that purpose only.
157177
158178When distributing tests on the local machine using ``pytest-xdist ``, care is taken to
159179automatically configure a `basetemp ` directory for the sub processes such that all temporary
0 commit comments