Commit 9ef5d330 authored by Michael Foord's avatar Michael Foord

unittest TestLoader test discovery filename matching done in a method. This...

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.
parent d5adb5d7
...@@ -230,6 +230,10 @@ class TestLoader(object): ...@@ -230,6 +230,10 @@ class TestLoader(object):
__import__(name) __import__(name)
return sys.modules[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): def _find_tests(self, start_dir, pattern):
"""Used by discovery. Yields test suites it loads.""" """Used by discovery. Yields test suites it loads."""
paths = os.listdir(start_dir) paths = os.listdir(start_dir)
...@@ -240,8 +244,8 @@ class TestLoader(object): ...@@ -240,8 +244,8 @@ class TestLoader(object):
if not VALID_MODULE_NAME.match(path): if not VALID_MODULE_NAME.match(path):
# valid Python identifiers only # valid Python identifiers only
continue continue
if not self._match_path(path, full_path, pattern):
if fnmatch(path, pattern): continue
# if the test file matches, load it # if the test file matches, load it
name = self._get_name_from_path(full_path) name = self._get_name_from_path(full_path)
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment