cpython: efc9836e0c83 (original) (raw)
Mercurial > cpython
changeset 100539:efc9836e0c83 3.5
#25320: Handle sockets in directories unittest discovery is scanning. Patch from Victor van den Elzen. [#25320]
Robert Collins rbtcollins@hp.com | |
---|---|
date | Tue, 15 Mar 2016 13:29:17 +1300 |
parents | 496e419860de |
children | 1d72402c1c91 4cabf12b7fc6 |
files | Lib/unittest/loader.py Lib/unittest/test/test_discovery.py Misc/ACKS Misc/NEWS |
diffstat | 4 files changed, 46 insertions(+), 0 deletions(-)[+] [-] Lib/unittest/loader.py 2 Lib/unittest/test/test_discovery.py 40 Misc/ACKS 1 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -479,6 +479,8 @@ class TestLoader(object): return tests, True finally: self._loading_packages.discard(name)
else:[](#l1.7)
return None, False[](#l1.8)
defaultTestLoader = TestLoader()
--- a/Lib/unittest/test/test_discovery.py +++ b/Lib/unittest/test/test_discovery.py @@ -90,6 +90,46 @@ class TestDiscovery(unittest.TestCase): ('test3', 'test4')]) self.assertEqual(suite, expected)
- def test_find_tests_socket(self):
# A socket is neither a directory nor a regular file.[](#l2.8)
# https://bugs.python.org/issue25320[](#l2.9)
loader = unittest.TestLoader()[](#l2.10)
original_listdir = os.listdir[](#l2.12)
def restore_listdir():[](#l2.13)
os.listdir = original_listdir[](#l2.14)
original_isfile = os.path.isfile[](#l2.15)
def restore_isfile():[](#l2.16)
os.path.isfile = original_isfile[](#l2.17)
original_isdir = os.path.isdir[](#l2.18)
def restore_isdir():[](#l2.19)
os.path.isdir = original_isdir[](#l2.20)
path_lists = [['socket']][](#l2.22)
os.listdir = lambda path: path_lists.pop(0)[](#l2.23)
self.addCleanup(restore_listdir)[](#l2.24)
os.path.isdir = lambda path: False[](#l2.26)
self.addCleanup(restore_isdir)[](#l2.27)
os.path.isfile = lambda path: False[](#l2.29)
self.addCleanup(restore_isfile)[](#l2.30)
loader._get_module_from_name = lambda path: path + ' module'[](#l2.32)
orig_load_tests = loader.loadTestsFromModule[](#l2.33)
def loadTestsFromModule(module, pattern=None):[](#l2.34)
# This is where load_tests is called.[](#l2.35)
base = orig_load_tests(module, pattern=pattern)[](#l2.36)
return base + [module + ' tests'][](#l2.37)
loader.loadTestsFromModule = loadTestsFromModule[](#l2.38)
loader.suiteClass = lambda thing: thing[](#l2.39)
top_level = os.path.abspath('/foo')[](#l2.41)
loader._top_level_dir = top_level[](#l2.42)
suite = list(loader._find_tests(top_level, 'test*.py'))[](#l2.43)
self.assertEqual(suite, [])[](#l2.45)
+ def test_find_tests_with_package(self): loader = unittest.TestLoader()
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -393,6 +393,7 @@ Lance Ellinghaus Daniel Ellis Phil Elson David Ely +Victor van den Elzen Jeff Epler Tom Epperly Gökcen Eraslan
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -91,6 +91,9 @@ Core and Builtins Library ------- +- Issue #25320: Handle sockets in directories unittest discovery is scanning.