Commit 232c7d0a authored by Robert Collins's avatar Robert Collins

#25320: Handle sockets in directories unittest discovery is scanning.

Patch from Victor van den Elzen.
parents 0e912a54 e20f0e7b
...@@ -479,6 +479,8 @@ class TestLoader(object): ...@@ -479,6 +479,8 @@ class TestLoader(object):
return tests, True return tests, True
finally: finally:
self._loading_packages.discard(name) self._loading_packages.discard(name)
else:
return None, False
defaultTestLoader = TestLoader() defaultTestLoader = TestLoader()
......
...@@ -90,6 +90,46 @@ class TestDiscovery(unittest.TestCase): ...@@ -90,6 +90,46 @@ class TestDiscovery(unittest.TestCase):
('test3', 'test4')]) ('test3', 'test4')])
self.assertEqual(suite, expected) self.assertEqual(suite, expected)
def test_find_tests_socket(self):
# A socket is neither a directory nor a regular file.
# https://bugs.python.org/issue25320
loader = unittest.TestLoader()
original_listdir = os.listdir
def restore_listdir():
os.listdir = original_listdir
original_isfile = os.path.isfile
def restore_isfile():
os.path.isfile = original_isfile
original_isdir = os.path.isdir
def restore_isdir():
os.path.isdir = original_isdir
path_lists = [['socket']]
os.listdir = lambda path: path_lists.pop(0)
self.addCleanup(restore_listdir)
os.path.isdir = lambda path: False
self.addCleanup(restore_isdir)
os.path.isfile = lambda path: False
self.addCleanup(restore_isfile)
loader._get_module_from_name = lambda path: path + ' module'
orig_load_tests = loader.loadTestsFromModule
def loadTestsFromModule(module, pattern=None):
# This is where load_tests is called.
base = orig_load_tests(module, pattern=pattern)
return base + [module + ' tests']
loader.loadTestsFromModule = loadTestsFromModule
loader.suiteClass = lambda thing: thing
top_level = os.path.abspath('/foo')
loader._top_level_dir = top_level
suite = list(loader._find_tests(top_level, 'test*.py'))
self.assertEqual(suite, [])
def test_find_tests_with_package(self): def test_find_tests_with_package(self):
loader = unittest.TestLoader() loader = unittest.TestLoader()
......
...@@ -396,6 +396,7 @@ Lance Ellinghaus ...@@ -396,6 +396,7 @@ Lance Ellinghaus
Daniel Ellis Daniel Ellis
Phil Elson Phil Elson
David Ely David Ely
Victor van den Elzen
Jeff Epler Jeff Epler
Tom Epperly Tom Epperly
Gökcen Eraslan Gökcen Eraslan
......
...@@ -218,6 +218,9 @@ Core and Builtins ...@@ -218,6 +218,9 @@ Core and Builtins
Library Library
------- -------
- Issue #25320: Handle sockets in directories unittest discovery is scanning.
Patch from Victor van den Elzen.
- Issue #16181: cookiejar.http2time() now returns None if year is higher than - Issue #16181: cookiejar.http2time() now returns None if year is higher than
datetime.MAXYEAR. datetime.MAXYEAR.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment