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:
Michael Foord 2010-06-05 10:39:42 +00:00
parent d5adb5d73d
commit 9ef5d33084

View file

@ -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: