summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/loader.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 10:45:41 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-06-05 10:45:41 (GMT)
commit4107d31db6a0a0ce4f720ec1f6a8f62f72f5b1ce (patch)
treefc2c4586bc0b2d45406955af270812c4e415c39a /Lib/unittest/loader.py
parent6f889ad32f5297f9e0775df3477788a7e19bcac3 (diff)
downloadcpython-4107d31db6a0a0ce4f720ec1f6a8f62f72f5b1ce.zip
cpython-4107d31db6a0a0ce4f720ec1f6a8f62f72f5b1ce.tar.gz
cpython-4107d31db6a0a0ce4f720ec1f6a8f62f72f5b1ce.tar.bz2
Merged revisions 81724 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81724 | michael.foord | 2010-06-05 11:39:42 +0100 (Sat, 05 Jun 2010) | 1 line 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. ........
Diffstat (limited to 'Lib/unittest/loader.py')
-rw-r--r--Lib/unittest/loader.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index 76c4e11..bff7b0a 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -235,6 +235,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)
@@ -245,26 +249,26 @@ class TestLoader(object):
if not VALID_MODULE_NAME.match(path):
# valid Python identifiers only
continue
-
- if fnmatch(path, pattern):
- # if the test file matches, load it
- name = self._get_name_from_path(full_path)
- try:
- module = self._get_module_from_name(name)
- except:
- yield _make_failed_import_test(name, self.suiteClass)
- else:
- mod_file = os.path.abspath(getattr(module, '__file__', full_path))
- realpath = os.path.splitext(mod_file)[0]
- fullpath_noext = os.path.splitext(full_path)[0]
- if realpath.lower() != fullpath_noext.lower():
- module_dir = os.path.dirname(realpath)
- mod_name = os.path.splitext(os.path.basename(full_path))[0]
- expected_dir = os.path.dirname(full_path)
- msg = ("%r module incorrectly imported from %r. Expected %r. "
- "Is this module globally installed?")
- raise ImportError(msg % (mod_name, module_dir, expected_dir))
- yield self.loadTestsFromModule(module)
+ 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:
+ module = self._get_module_from_name(name)
+ except:
+ yield _make_failed_import_test(name, self.suiteClass)
+ else:
+ mod_file = os.path.abspath(getattr(module, '__file__', full_path))
+ realpath = os.path.splitext(mod_file)[0]
+ fullpath_noext = os.path.splitext(full_path)[0]
+ if realpath.lower() != fullpath_noext.lower():
+ module_dir = os.path.dirname(realpath)
+ mod_name = os.path.splitext(os.path.basename(full_path))[0]
+ expected_dir = os.path.dirname(full_path)
+ msg = ("%r module incorrectly imported from %r. Expected %r. "
+ "Is this module globally installed?")
+ raise ImportError(msg % (mod_name, module_dir, expected_dir))
+ yield self.loadTestsFromModule(module)
elif os.path.isdir(full_path):
if not os.path.isfile(os.path.join(full_path, '__init__.py')):
continue