pytest-dev / pytest-dev/pytest

tmp_path: basetemp with retention

Open
#10,829 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: tmpdir status: help wanted type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

from the tmp_path how-to docs:

Temporary directories are by default created as sub-directories of the system temporary directory. ... entries older than 3 temporary directories will be removed. ... can be configured with tmp_path_retention_count ...

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.

Is there any particular reason that the retention feature (keep 3 by default) is not supported when --basetemp is used?
It seems like these features should be orthogonal, but that's not the case which is counter-intuitive.

Current workaround is apparently to use the PYTEST_DEBUG_TEMPROOT env var instead of --basetemp but that feature is not documented as far as I could find.

I understand that there are concerns about backward compatibility, but I think basetemp+retention can be implented in a backward compatible way:

  • use --basetemp, but no tmp_path_retention_count config set: use custom temp root without retention (existing behavior)
  • use --basetemp and tmp_path_retention_count: use custom temp root with retention (this feature request)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tmp_path how-to docs and trace the existing --basetemp and tmp_path_retention_count handling. Check how PYTEST_DEBUG_TEMPROOT is used, then determine where coverage should verify the proposed backward-compatible behavior. Done means basetemp honors retention when configured while preserving its current behavior when retention is unset.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.