Skip to content

Commit 3ad3161

Browse files
committed
Move validation of module filename to a helper function
1 parent efa9ecc commit 3ad3161

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/unittest/loader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def testFailure():
2929
return testFailure
3030

3131

32+
def _is_valid_module_filename(module_filename):
33+
root, ext = os.path.splitext(module_filename)
34+
if not (ext == '.py' and root.isidentifier()):
35+
return False
36+
return True
37+
3238
def _make_failed_import_test(name, suiteClass):
3339
message = 'Failed to import test module: %s\n%s' % (
3440
name, traceback.format_exc())
@@ -366,8 +372,7 @@ def _find_test_path(self, full_path, pattern):
366372
"""
367373
basename = os.path.basename(full_path)
368374
if os.path.isfile(full_path):
369-
root, ext = os.path.splitext(basename)
370-
if not (ext == '.py' and root.isidentifier()):
375+
if not _is_valid_module_filename(basename):
371376
# valid Python identifiers only
372377
return None, False
373378
if not self._match_path(basename, full_path, pattern):

0 commit comments

Comments
 (0)