From 62e75c7d55cabaaba33c37b1551ff987f7e45a23 Mon Sep 17 00:00:00 2001 From: Yusuke Kadowaki Date: Thu, 1 Dec 2022 22:29:46 +0900 Subject: [PATCH] Documentation update for tmp_path configurations --- doc/en/how-to/tmp_path.rst | 9 ++++++--- src/_pytest/tmpdir.py | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/en/how-to/tmp_path.rst b/doc/en/how-to/tmp_path.rst index a2f936d33..21be898f6 100644 --- a/doc/en/how-to/tmp_path.rst +++ b/doc/en/how-to/tmp_path.rst @@ -131,10 +131,13 @@ The default base temporary directory Temporary directories are by default created as sub-directories of the system temporary directory. The base name will be ``pytest-NUM`` where -``NUM`` will be incremented with each test run. Moreover, entries older -than 3 temporary directories will be removed. +``NUM`` will be incremented with each test run. +By default, only the directories of failed tests will be kept. +Also only the last 3 directries will remain at most. +This behavior can be configured with :confval:`tmp_path_retention_count` and +:confval:`tmp_path_retention_policy`. -The number of entries currently cannot be changed, but using the ``--basetemp`` +Using the ``--basetemp`` option will remove the directory before every run, effectively meaning the temporary directories of only the most recent run will be kept. diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 48670b6c4..57671483f 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -267,8 +267,10 @@ def tmp_path( directory. By default, a new base temporary directory is created each test session, - and old bases are removed after 3 sessions, to aid in debugging. If - ``--basetemp`` is used then it is cleared each session. See :ref:`base + and only the base of failed session is kept. Also it only keeps the last 3 bases + at most. This can be configured with :confval:`tmp_path_retention_count` and + :confval:`tmp_path_retention_policy`. + If ``--basetemp`` is used then it is cleared each session. See :ref:`base temporary directory`. The returned object is a :class:`pathlib.Path` object.