CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
785 stars 75 forks source link

Green leaves empty temp files in /tmp #228

Closed lcerman closed 3 years ago

lcerman commented 3 years ago

After running green an empty tmpdir remain in /tmp for each test file executed. E.g., if I have project with 10 test files, 10 empty directories remains after running green. In a larger project it soon reaches thousands of empty directories in tmp after a while...

Steps to reproduce:

  1. create testfile.py:
    
    import unittest

class Test(unittest.TestCase): def test(self): pass


2. run `green testfile.py`

An empty tmp* directory is left in /tmp.

Our green config file:

verbose = 2 file-pattern = _test.py omit-patterns = _test.py

$ green --version Green 3.2.0, Coverage 5.1, Python 3.7.5



Note: when running the test with standard unittest module no empty dir remains, it seems to be issue of green not unittest module.
lcerman commented 3 years ago

I have just found that the temp dirs are intentionally not removed by the poolRunner when the Python 3 is detected. Also found one older attempt to fix this here #173.

If that is problem of macOS why not narrow the condition skipping temp removal for macOS only? Leaving thousands of empty temp directories after multiple runs of the tests is somewhat annoying...

CleanCut commented 3 years ago

@lcerman It's extremely annoying. Unfortunately, it's also disturbingly hard to fix. I've spent days on this in the past. Take a look at what happens if I just try to naively clean up files and ignore errors --> 💥 ... and not just on macOS.

Perhaps it just needs a fresh pair of eyes! Would you like to give it a try? We all have our blind spots, so maybe you'll find a way that I missed. If you fork and make a PR, any commit you push to your fork should trigger CI on TravisCI and AppVeyor so you can see whether anything breaks or not.

image
lcerman commented 3 years ago

Finally, I am back with a solution: https://github.com/CleanCut/green/pull/232

The solution is pragmatic -- rather than trying to remove the temp-dirs in the workers a single temp-dir is created by the main function. The workers continue to create their own temps as sub-directories of the main temp, which is then removed when the main function finishes.

CleanCut commented 3 years ago

Awesome! Thank you so much. That's a nice solution.

CleanCut commented 3 years ago

The fix is included in 3.2.3, just released.