Skip to content
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

delete files that are no longer needed #30

Closed
luerhard opened this issue May 20, 2020 · 5 comments
Closed

delete files that are no longer needed #30

luerhard opened this issue May 20, 2020 · 5 comments

Comments

@luerhard
Copy link

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.

@nicoddemus
Copy link
Member

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. 👍

@luerhard
Copy link
Author

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.

@tovrstra
Copy link
Contributor

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.

@12rambau
Copy link
Contributor

12rambau commented Jan 20, 2025

I myself thought the same when I started using the lib but now that I'm doing more complex stuff with datadir you would definitely not be able to make the diffrence between what was generated by this lib and the others. As a user I would really like this feature NOT to be implemented as it will surely break downstream stuff.

@luerhard
Copy link
Author

luerhard commented Feb 4, 2025

Reading this discussion, I see three options:

  1. no implement the feature at all.
  2. use a subdirectory that is only dedicated to generated files and can be cleaned. Such a subdirectory like e.g. datadir/_pytestreg_managed could then be stripped from all unwanted files.
  3. create and manage a list of files that were generated by pytest-regression. Such a list would allow pytest-regressions to remove files that were generated by it but no longer needed.

@luerhard luerhard closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants