summaryrefslogtreecommitdiffstats
path: root/Lib/test/regrtest.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2002-07-30 23:27:12 (GMT)
committerBarry Warsaw <barry@python.org>2002-07-30 23:27:12 (GMT)
commit408b6d34de2b1a6ba690557def435adce9314184 (patch)
tree9d4e40110765646f7033a740641ef67750d17b91 /Lib/test/regrtest.py
parent1bc894b1333ff0fd0d8b175f6748798e5fd08aed (diff)
downloadcpython-408b6d34de2b1a6ba690557def435adce9314184.zip
cpython-408b6d34de2b1a6ba690557def435adce9314184.tar.gz
cpython-408b6d34de2b1a6ba690557def435adce9314184.tar.bz2
Complete the absolute import patch for the test suite. All relative
imports of test modules now import from the test package. Other related oddities are also fixed (like DeprecationWarning filters that weren't specifying the full import part, etc.). Also did a general code cleanup to remove all "from test.test_support import *"'s. Other from...import *'s weren't changed.
Diffstat (limited to 'Lib/test/regrtest.py')
-rwxr-xr-xLib/test/regrtest.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 4d71e21..1fa5d50 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -244,8 +244,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
print "All",
print count(len(good), "test"), "OK."
if verbose:
- print "CAUTION: stdout isn't compared in verbose mode: a test"
- print "that passes in verbose mode may fail without it."
+ print "CAUTION: stdout isn't compared in verbose mode:"
+ print "a test that passes in verbose mode may fail without it."
if bad:
print count(len(bad), "test"), "failed:"
printlist(bad)
@@ -338,7 +338,13 @@ def runtest(test, generate, verbose, quiet, testdir = None):
if cfp:
sys.stdout = cfp
print test # Output file starts with test name
- the_module = __import__(test, globals(), locals(), [])
+ if test.startswith('test.'):
+ abstest = test
+ else:
+ # Always import it from the test package
+ abstest = 'test.' + test
+ the_package = __import__(abstest, globals(), locals(), [])
+ the_module = getattr(the_package, test)
# Most tests run to completion simply as a side-effect of
# being imported. For the benefit of tests that can't run
# that way (like test_threaded_import), explicitly invoke
@@ -784,4 +790,18 @@ class _ExpectedSkips:
return self.expected
if __name__ == '__main__':
+ # Remove regrtest.py's own directory from the module search path. This
+ # prevents relative imports from working, and relative imports will screw
+ # up the testing framework. E.g. if both test.test_support and
+ # test_support are imported, they will not contain the same globals, and
+ # much of the testing framework relies on the globals in the
+ # test.test_support module.
+ mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
+ i = pathlen = len(sys.path)
+ while i >= 0:
+ i -= 1
+ if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
+ del sys.path[i]
+ if len(sys.path) == pathlen:
+ print 'Could not find %r in sys.path to remove it' % mydir
main()