_Original comment by_ Jurko Gospodneti膰 (BitBucket: jurko, GitHub: jurko):
I think pytest already does that. It just keeps the temporary test data around for the last few (5?) test runs, but all the ones before that are removed automatically. I haven't checked the source code, but I think that's how pytest behaves for me - Windows 7 installation.
IMO, retaining the temporary test data for the last few test runs is extremely useful when you need to debug a specific test failure.
Just my 2 cents worth...
Best regards,
Jurko Gospodneti膰
I get that some people would prefer to keep some old test run data around. However frequently I have big test data and would like to have it cleaned up (particularly if the tests all pass). Is there a way for one to force cleanup after a run?
Currently not, but it is easy to add a new ini option that tells pytest how many previous versions to keep around:
[pytest]
tmpdir_keep=0
Currently the default is 3.
my pytest version is 4.3.1
but not work
$ ls -l
total 0
drwxr-xr-x 6 scottming staff 192B Mar 21 19:37 pytest-12
drwxr-xr-x 6 scottming staff 192B Mar 21 19:37 pytest-13
drwxr-xr-x 6 scottming staff 192B Mar 21 19:38 pytest-14
lrwxr-xr-x 1 scottming staff 86B Mar 21 19:38 pytest-current -> /private/var/folders/tf/2yqh3xmj5sl7rb3pbsv_p_ww0000gp/T/pytest-of-scottming/pytest-14
this is the content in my pytest.ini file:
[pytest]
tmpdir_keep=0
this is the test code:
CONTENT = "content"
def test_create_file(tmp_path):
print('tmp_path"', tmp_path)
d = tmp_path / "sub"
d.mkdir()
p = d / "hello.txt"
p.write_text(CONTENT)
assert p.read_text() == CONTENT
assert len(list(tmp_path.iterdir())) == 1
assert 0
Hi @scottming,
The tmpdir_keep option does not exist, it was merely a suggestion in https://github.com/pytest-dev/pytest/issues/543#issuecomment-306644153 as something that could be implemented. 馃槈
Most helpful comment
Currently not, but it is easy to add a new
inioption that tells pytest how many previous versions to keep around:Currently the default is
3.