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 11:46:20 2015 +0300 @@ -126,7 +126,10 @@ tests = self.suiteClass(tests) if load_tests is not None: try: - return load_tests(self, tests, pattern) + # load_tests may call loader.discover which changes self._top_level_dir + _top_level_dir = self._top_level_dir + tests = load_tests(self, tests, pattern) + self._top_level_dir = _top_level_dir except Exception as e: error_case, error_message = _make_failed_load_tests( module.__name__, e, self.suiteClass) @@ -451,9 +454,6 @@ msg % (mod_name, module_dir, expected_dir)) return self.loadTestsFromModule(module, pattern=pattern), False elif os.path.isdir(full_path): - if (not namespace and - not os.path.isfile(os.path.join(full_path, '__init__.py'))): - return None, False load_tests = None tests = None diff -r 293d9964cf6e Lib/unittest/test/test_discovery.py --- a/Lib/unittest/test/test_discovery.py Tue Apr 28 00:04:53 2015 -0400 +++ b/Lib/unittest/test/test_discovery.py Tue Apr 28 11:46:20 2015 +0300 @@ -53,7 +53,7 @@ os.path.isdir = original_isdir path_lists = [['test2.py', 'test1.py', 'not_a_test.py', 'test_dir', - 'test.foo', 'test-not-a-module.py', 'another_dir'], + 'test.foo', 'test-not-a-module.py', 'another_dir'], [], ['test4.py', 'test3.py', ]] os.listdir = lambda path: path_lists.pop(0) self.addCleanup(restore_listdir) @@ -65,7 +65,7 @@ def isfile(path): # another_dir is not a package and so shouldn't be recursed into - return not path.endswith('dir') and not 'another_dir' in path + return not path.endswith('dir') os.path.isfile = isfile self.addCleanup(restore_isfile) @@ -85,7 +85,7 @@ # The test suites found should be sorted alphabetically for reliable # execution order. expected = [[name + ' module tests'] for name in - ('test1', 'test2', 'test_dir')] + ('another_dir', 'test1', 'test2', 'test_dir')] expected.extend([[('test_dir.%s' % name) + ' module tests'] for name in ('test3', 'test4')]) self.assertEqual(suite, expected)