summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/loader.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-05-07 23:42:40 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-05-07 23:42:40 (GMT)
commit3b2494f38c17ad9d673a1b8cac8d4143ba06e3df (patch)
tree332153c9f4cb64630cde3b29c61ca66c750b3a75 /Lib/unittest/loader.py
parent135d87c23cd7e486d8b85adc0488f4fef1dbdc60 (diff)
downloadcpython-3b2494f38c17ad9d673a1b8cac8d4143ba06e3df.zip
cpython-3b2494f38c17ad9d673a1b8cac8d4143ba06e3df.tar.gz
cpython-3b2494f38c17ad9d673a1b8cac8d4143ba06e3df.tar.bz2
Merged revisions 80946 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80946 | michael.foord | 2010-05-08 01:39:38 +0200 (Sat, 08 May 2010) | 1 line Issue 8547 - detecting and reporting that modules have been imported from the wrong location under test discovery. ........
Diffstat (limited to 'Lib/unittest/loader.py')
-rw-r--r--Lib/unittest/loader.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index a45dffa..76c4e11 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -178,7 +178,10 @@ class TestLoader(object):
if not top_level_dir in sys.path:
# all test modules must be importable from the top level directory
- sys.path.append(top_level_dir)
+ # should we *unconditionally* put the start directory in first
+ # in sys.path to minimise likelihood of conflicts between installed
+ # modules and development versions?
+ sys.path.insert(0, top_level_dir)
self._top_level_dir = top_level_dir
is_not_importable = False
@@ -251,6 +254,16 @@ class TestLoader(object):
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')):