CleanCut / green

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

Unconditionally cleanup temp folder in poolRunner #173

Closed althonos closed 6 years ago

althonos commented 6 years ago

Hi Nathan, because of a conditional branch the temporary directories that a poolRunner call creates are not properly created in Python 3. When running tests several times, the /tmp (or equivalent) directory can become cluttered very quickly. I removed the if branching so that the temporary folder is always removed.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 6ffde65afa88e55c2fd1c0cfd166c9c8e2483e9c on althonos:patch-1 into d260d273f22401fe64b9969f5b26a55cd1db9dfe on CleanCut:master.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 185b52653ba3ba8bc874519bb835f1edc148d077 on althonos:patch-1 into d260d273f22401fe64b9969f5b26a55cd1db9dfe on CleanCut:master.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 185b52653ba3ba8bc874519bb835f1edc148d077 on althonos:patch-1 into d260d273f22401fe64b9969f5b26a55cd1db9dfe on CleanCut:master.

CleanCut commented 6 years ago

Unfortunately, that (somewhat perplexingly) breaks skipping tests from setUpClass class methods on Python 3 on macOS.

It consistently fails on both Travis and on my MacBook Pro.

I think the fact that I couldn't figure out why it broke it is why that seemingly-silly if statement was there in the first place.

Lets take another look and see if we can fix the actual problem, instead of leaving temp files around.

venv3.6/bin/python -m green.cmdline -s 0 -k green
...................................................................................................s.....................................
...................................................E..........sTraceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/util.py", line 262, in _run_finalizers
    finalizer()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/util.py", line 186, in __call__
    res = self._callback(*self._args, **self._kwargs)
  File "/Users/nathan/proj/green/venv3.6/lib/python3.6/shutil.py", line 471, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "/Users/nathan/proj/green/venv3.6/lib/python3.6/shutil.py", line 469, in rmtree
    orig_st = os.lstat(path)
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/8y/cgqfhxyn2fz3r8n627_6dm_m0000gn/T/tmpdc5m6xlx/pymp-ljgmarin'

Error in green.test.test_suite.TestFunctional.test_skip_in_setUpClass
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/nathan/proj/green/green/test/test_suite.py", line 158, in test_skip_in_setUpClass
    result = run(tests, self.stream, self.args)
  File "/Users/nathan/proj/green/green/runner.py", line 91, in run
    manager = multiprocessing.Manager()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/context.py", line 56, in Manager
    m.start()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/managers.py", line 517, in start
    self._address = reader.recv()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 250, in recv
    buf = self._recv_bytes()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 407, in _recv_bytes
    buf = self._recv(4)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError

Ran 200 tests in 3.258s

FAILED (errors=1, passes=197, skips=2)
althonos commented 6 years ago

@CleanCut : I can't help you with that, I have no way to test on MacOS. What about reverting to

if sys.platform != 'darwin' or sys.version_info[0] == 2: # pragma: no cover
    shutil.rmtree(tempfile.tempdir, ignore_errors=True)

as a temporary patch ?

CleanCut commented 6 years ago

@althonos Sure, lets do that. I'd prefer actually fixing it for reals somehow, but I'm swamped right now. Lets add a # TODO: Make this not necessary on macOS+Python 3 so we can actually clean up after ourselves

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 653dd43d62dfe2e37fdeca45516395de8fb87a93 on althonos:patch-1 into d260d273f22401fe64b9969f5b26a55cd1db9dfe on CleanCut:master.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 653dd43d62dfe2e37fdeca45516395de8fb87a93 on althonos:patch-1 into d260d273f22401fe64b9969f5b26a55cd1db9dfe on CleanCut:master.

CleanCut commented 6 years ago

Included in 2.11.2, just released.

CleanCut commented 5 years ago

I had to revert this commit in 2.13.1, as it was breaking Green on some setups. Do you want to look at this again with 2.13.1 and see if you still see a buildup of extra temporary directories?