pytest-regressions
pytest-regressions copied to clipboard
delete files that are no longer needed
It would be supernice, if there was a way to automatically remove files (and directories) that are leftover from tests that do not exist anymore. Tests are renamed regularly and after that you (or at least I) have a lot of leftover datafiles that I need to remove manually.
Hi @luerhard,
Thanks for the suggestion!
I've felt this need myself in the past, but there are a few details that complicate things:
- The data directories might contain files other than the ones handled by pytest-regressions, so it is not really safe for us to remove anything there, I believe.
- The data directory is managed by
pytest-datadir
, so my impression is that it would need some sort of similar feature in there, that might overlap here (for example, deletedata_
directories which don't have an associatedtest_
file).
Those are my thoughts, but feel free to suggest solutions if you come up with anything. 👍
Hi @nicoddemus, thanks for the reply ! A few thoughts on that: I am not really sure why someone would store any files other than pytest-regressions data files in those folders. Is there any good reason for this? If there is, I see two possibilities to handle that:
- either one has to track all created files in a
.pytest_reg
file or database or something similar - or we could hide the
data_
directories as.data_
directories to point out that nobody should store anything else inside apart from the test-data-files.
This would be an interesting feature, but other tests using pytest-datadir use files in the same data_*
directory. For example:
def test_read_module(datadir):
contents = (datadir / 'spam.txt').read_text()
assert contents == 'eggs\n'
def test_data(data_regression):
data = {"foo": 1}
data_regression.check(data)
That makes automatic cleaning potentially dangerous.