CleanCut / green

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

Incompatibility with pyfakefs for Python 2.7 #221

Closed SebiSebi closed 4 years ago

SebiSebi commented 4 years ago

I am using green as a test runner on Travis CI. I have noticed a problem when testing on a mock file-system (using pyfakefs). Code to reproduce the issue:

import unittest

from pyfakefs.fake_filesystem_unittest import TestCase

class TestExample(TestCase):

    def setUp(self):
        self.setUpPyfakefs()

    def test_something(self):
        self.assertEqual(2 * 2, 4)

if __name__ == '__main__':
    unittest.main()

Running python test_example.py works fine. However, running green fails with this trace:

Traceback (most recent call last):
  File "/home/sebisebi/test_green/env/local/lib/python2.7/site-packages/green/process.py", line 45, in __call__
    result = self.__callable(*args, **kwargs)
  File "/home/sebisebi/test_green/env/local/lib/python2.7/site-packages/green/process.py", line 363, in poolRunner
    cleanup()
  File "/home/sebisebi/test_green/env/local/lib/python2.7/site-packages/green/process.py", line 273, in cleanup
    shutil.rmtree(tempfile.tempdir, ignore_errors=True)
  File "/usr/lib/python2.7/shutil.py", line 251, in rmtree
    if os.path.islink(path):
  File "/home/sebisebi/test_green/env/lib/python2.7/posixpath.py", line 135, in islink
    st = os.lstat(path)
TypeError: coercing to Unicode: need string or buffer, NoneType found

This only happens on Python 2.7.

I know that Python 2.7 reached the end of its life on January 1st, 2020 but it would be nice to fix this issue if not a lot of work is involved.

SebiSebi commented 4 years ago

The error is deterministic, it happends 100% of time on Python 2.7.

It never happened on Python 3+.

CleanCut commented 4 years ago

Can do. Since the crash was happening in a Python 2-specific block during a tempfile cleanup, I went ahead and added a try block to just catch and ignore the error. Version 3.1.2 has the fix -- give it a try.

SebiSebi commented 4 years ago

Awesome! It looks fixed. Thanks!