mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
unittest TestLoader test discovery filename matching done in a method. This makes it easier to override the matching strategy in subclasses. No behaviour change in actual implementation.
This commit is contained in:
parent
d5adb5d73d
commit
9ef5d33084
1 changed files with 24 additions and 20 deletions
|
@ -230,6 +230,10 @@ class TestLoader(object):
|
|||
__import__(name)
|
||||
return sys.modules[name]
|
||||
|
||||
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):
|
||||
"""Used by discovery. Yields test suites it loads."""
|
||||
paths = os.listdir(start_dir)
|
||||
|
@ -240,8 +244,8 @@ class TestLoader(object):
|
|||
if not VALID_MODULE_NAME.match(path):
|
||||
# valid Python identifiers only
|
||||
continue
|
||||
|
||||
if fnmatch(path, pattern):
|
||||
if not self._match_path(path, full_path, pattern):
|
||||
continue
|
||||
# if the test file matches, load it
|
||||
name = self._get_name_from_path(full_path)
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue