pytest-regressions icon indicating copy to clipboard operation
pytest-regressions copied to clipboard

delete files that are no longer needed

Open luerhard opened this issue 4 years ago • 3 comments

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.

luerhard avatar May 20 '20 11:05 luerhard

Hi @luerhard,

Thanks for the suggestion!

I've felt this need myself in the past, but there are a few details that complicate things:

  1. 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.
  2. 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, delete data_ directories which don't have an associated test_ file).

Those are my thoughts, but feel free to suggest solutions if you come up with anything. 👍

nicoddemus avatar May 20 '20 14:05 nicoddemus

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.

luerhard avatar May 23 '20 09:05 luerhard

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.

tovrstra avatar Sep 15 '21 20:09 tovrstra