[issue23882] unittest discovery doesn't detect namespace packages when given no parameters

Md Jony Hossain Habib report at bugs.python.org
Mon Feb 22 15:14:28 EST 2021


Md Jony Hossain Habib <mdjonyhossainhabib at gmail.com> added the comment:

diff -r 293d9964cf6e Lib/unittest/loader.py
--- a/Lib/unittest/loader.py	Tue Apr 28 00:04:53 2015 -0400
+++ b/Lib/unittest/loader.py	Tue Apr 28 10:12:07 2015 +0300
@@ -338,7 +338,7 @@
             raise ImportError('Start directory is not importable: %r' % start_dir)
 
         if not is_namespace:
-            tests = list(self._find_tests(start_dir, pattern))
+            tests = list(self._find_tests(start_dir, pattern, namespace=True))
         return self.suiteClass(tests)
 
     def _get_directory_containing_module(self, module_name):
@@ -403,7 +403,7 @@
                 name = self._get_name_from_path(full_path)
                 self._loading_packages.add(name)
                 try:
-                    yield from self._find_tests(full_path, pattern, namespace)
+                    yield from self._find_tests(full_path, pattern, False)
                 finally:
                     self._loading_packages.discard(name)
 
diff -r 293d9964cf6e Lib/unittest/test/test_program.py
--- a/Lib/unittest/test/test_program.py	Tue Apr 28 00:04:53 2015 -0400
+++ b/Lib/unittest/test/test_program.py	Tue Apr 28 10:12:07 2015 +0300
@@ -16,7 +16,7 @@
         expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))
 
         self.wasRun = False
-        def _find_tests(start_dir, pattern):
+        def _find_tests(start_dir, pattern, namespace):
             self.wasRun = True
             self.assertEqual(start_dir, expectedPath)
             return tests

----------
nosy: +mdjonyhossainhabib

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue23882>
_______________________________________


More information about the Python-bugs-list mailing list