Skip to content

Should tmpdir clean up after itself? #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pytestbot opened this issue Jul 21, 2014 · 10 comments
Closed

Should tmpdir clean up after itself? #543

pytestbot opened this issue Jul 21, 2014 · 10 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Christian Theune (BitBucket: ctheune, GitHub: ctheune)


We noticed that tmpdir isn't cleaning up after itself.

Is there a reason why not? The docs don't mention it. Otherwise: I'd be happy to provide a patch to make tmpdir clean up after itself.


@pytestbot
Copy link
Contributor Author

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ć

@pytestbot
Copy link
Contributor Author

Original comment by Floris Bruynooghe (BitBucket: flub, GitHub: flub):


What @jurko says is correct AFAIK, only 5-7 versions are kept around and you get a simlink /tmp/pytest-<username> to the most recent one. So cleanup already happens just a little later then you might expect.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@jakirkham
Copy link

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?

@nicoddemus
Copy link
Member

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.

@scottming
Copy link

scottming commented Mar 21, 2019

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

@nicoddemus
Copy link
Member

Hi @scottming,

The tmpdir_keep option does not exist, it was merely a suggestion in #543 (comment) as something that could be implemented. 😉

@lazarillo
Copy link

Should these details -- that tmp_path, etc. keep the last few runs but then clean themselves up -- be documented somewhere? I did not see any documentation specifying it.

@The-Compiler
Copy link
Member

@lazarillo
Copy link

Thanks, @The-Compiler ! I read that section, but I guess I did not read carefully enough, as I did not notice the

Moreover, entries older than 3 temporary directories will be removed.

sentence.

keszybz added a commit to keszybz/systemd that referenced this issue Dec 8, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543
keszybz added a commit to systemd/systemd-stable that referenced this issue Dec 15, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543

(cherry picked from commit ef0a69e)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Dec 19, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543

(cherry picked from commit ef0a69e)
(cherry picked from commit d93341f)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Dec 19, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543

(cherry picked from commit ef0a69e)
(cherry picked from commit d93341f)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Dec 19, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543

(cherry picked from commit ef0a69e)
(cherry picked from commit d93341f)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Dec 20, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543

(cherry picked from commit ef0a69e)
(cherry picked from commit d93341f)
bluca pushed a commit to systemd/systemd-stable that referenced this issue Dec 22, 2023
pytest intentionally keeps around a limited number of the previous test
temporary directories [1]. This is generally OK, but in our tests that generate
initrds, we create a few very large files (both the initrd and kernel in a few
copies), which quickly adds up. I had a particularly large initrd (because of
some mkosi-initrd shenanigans), and I unded up with dozens of gigabytes of
temporary files from the tests. Let's just nuke the dirs where we write
kernel data.

[1] pytest-dev/pytest#543

(cherry picked from commit ef0a69e)
(cherry picked from commit d93341f)
@CarterFendley
Copy link

Adding comment because this is coming up in related Google searches.

There are two options which are now used to configure tmpdir retention:

  • tmp_path_retention_count
  • tmp_path_retention_policy

See retention reference and the issue which planned these updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

7 participants