Description
Originally reported by: Torsten Landschoff (BitBucket: bluehorn, GitHub: bluehorn)
We are currently juggling with big files in tests which we currently store in tmpdir.
This kills our Jenkins slaves because py.test will keep temporary files for 3 runs of each test suite. We are no up at > 10GB of temporary files for some projects per test run.
Keeping the temporary files is indeed a nice feature which we often use during TDD to find out what we were missing. But the temporary files of a passed test are 99.99% worthless for us.
Therefore I'd like to have a tmpdir fixture that cleans up the temporary files if the test was successful or skipped. Or have some options to configure how py.test handles temporary files wrt. what is kept.
As an intermediate step I am currently moving some pytest.fixture functions to clean up the temporary files after use, but I end up removing the files even if the test failed.
What I am also just realizing: We moved the temporary files inside the Jenkins workspace of each project to keep track of disk usage and for easy access via the web interface. If only temporary files for failed tests are kept, then we could archive them as build artifacts so that we can even diagnose tests that failed in the past.
I was thinking about something in the line of
#!python
@pytest.fixture
def database(request):
# Pull SQLite test database from somewhere
dbfile = "..."
def finalizer(testresult):
if testresult == "PASS":
os.unlink(dbfile)
request.addfinalizer(finalizer, parameters=["testresult"])
Alternatively, pytest could use introspection to inject the testresult if the finalizer takes a testresult argument.