Skip to content

Commit

Permalink
remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Oct 22, 2024
1 parent be8d0e7 commit d0b6e04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
1 change: 0 additions & 1 deletion Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ symtable

(Contributed by Bénédikt Tran in :gh:`120029`.)


unicodedata
-----------

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_unittest/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def restore_isdir():
self.addCleanup(restore_isdir)

_find_tests_args = []
def _find_tests(start_dir, pattern, namespace=None):
def _find_tests(start_dir, pattern):
_find_tests_args.append((start_dir, pattern))
return ['tests']
loader._find_tests = _find_tests
Expand Down Expand Up @@ -817,7 +817,7 @@ def test_discovery_from_dotted_path(self):
expectedPath = os.path.abspath(os.path.dirname(test.test_unittest.__file__))

self.wasRun = False
def _find_tests(start_dir, pattern, namespace=None):
def _find_tests(start_dir, pattern):
self.wasRun = True
self.assertEqual(start_dir, expectedPath)
return tests
Expand Down
17 changes: 7 additions & 10 deletions Lib/unittest/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
self._top_level_dir = \
(path.split(the_module.__name__
.replace(".", os.path.sep))[0])
tests.extend(self._find_tests(path, pattern, namespace=True))
tests.extend(self._find_tests(path, pattern))
elif the_module.__name__ in sys.builtin_module_names:
# builtin module
raise TypeError('Can not use builtin modules '
Expand Down Expand Up @@ -371,7 +371,7 @@ def _match_path(self, path, full_path, pattern):
# override this method to use alternative matching strategy
return fnmatch(path, pattern)

def _find_tests(self, start_dir, pattern, namespace=False):
def _find_tests(self, start_dir, pattern):
"""Used by discovery. Yields test suites it loads."""
# Handle the __init__ in this package
name = self._get_name_from_path(start_dir)
Expand All @@ -380,8 +380,7 @@ def _find_tests(self, start_dir, pattern, namespace=False):
if name != '.' and name not in self._loading_packages:
# name is in self._loading_packages while we have called into
# loadTestsFromModule with name.
tests, should_recurse = self._find_test_path(
start_dir, pattern, namespace)
tests, should_recurse = self._find_test_path(start_dir, pattern)
if tests is not None:
yield tests
if not should_recurse:
Expand All @@ -392,20 +391,19 @@ def _find_tests(self, start_dir, pattern, namespace=False):
paths = sorted(os.listdir(start_dir))
for path in paths:
full_path = os.path.join(start_dir, path)
tests, should_recurse = self._find_test_path(
full_path, pattern, False)
tests, should_recurse = self._find_test_path(full_path, pattern)
if tests is not None:
yield tests
if should_recurse:
# we found a package that didn't use load_tests.
name = self._get_name_from_path(full_path)
self._loading_packages.add(name)
try:
yield from self._find_tests(full_path, pattern, False)
yield from self._find_tests(full_path, pattern)
finally:
self._loading_packages.discard(name)

def _find_test_path(self, full_path, pattern, namespace=False):
def _find_test_path(self, full_path, pattern):
"""Used by discovery.
Loads tests from a single file, or a directories' __init__.py when
Expand Down Expand Up @@ -449,8 +447,7 @@ def _find_test_path(self, full_path, pattern, namespace=False):
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'))):
if not os.path.isfile(os.path.join(full_path, '__init__.py')):
return None, False

load_tests = None
Expand Down

0 comments on commit d0b6e04

Please sign in to comment.