Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (revision 78165) +++ Lib/test/regrtest.py (working copy) @@ -170,7 +170,7 @@ # happens before the chdir). All the modules imported after the chdir, are # not found in the CWD, and since the other paths in sys.path[1:] are absolute # (site.py absolutize them), the __file__ and __path__ will be absolute too. -# Therefore it is necessary to absolutize manually the __file__ and __path__ of +# Therefore it is necessary to absolutize the __file__ and __path__ of # the packages to prevent later imports to fail when the CWD is different. for module in sys.modules.itervalues(): if hasattr(module, '__path__'): @@ -404,10 +404,8 @@ fp.close() # Strip .py extensions. - if args: - args = map(removepy, args) - if tests: - tests = map(removepy, tests) + removepy(args) + removepy(tests) stdtests = STDTESTS[:] nottests = NOTTESTS[:] @@ -665,16 +663,15 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): """Return a list of all applicable test modules.""" - if not testdir: testdir = findtestdir() + testdir = findtestdir(testdir) names = os.listdir(testdir) tests = [] + others = set(stdtests + nottests) for name in names: - if name[:5] == "test_" and name[-3:] == os.extsep+"py": - modname = name[:-3] - if modname not in stdtests and modname not in nottests: - tests.append(modname) - tests.sort() - return stdtests + tests + modname, ext = os.path.splitext(name) + if modname[:5] == "test_" and ext == ".py" and modname not in others: + tests.append(modname) + return stdtests + sorted(tests) def runtest(test, verbose, quiet, testdir=None, huntrleaks=False, use_resources=None): @@ -825,8 +822,7 @@ def runtest_inner(test, verbose, quiet, testdir=None, huntrleaks=False): test_support.unload(test) - if not testdir: - testdir = findtestdir() + testdir = findtestdir(testdir) if verbose: capture_stdout = None else: @@ -1054,18 +1050,16 @@ # Collect cyclic trash. gc.collect() -def findtestdir(): - if __name__ == '__main__': - file = sys.argv[0] - else: - file = __file__ - testdir = os.path.dirname(file) or os.curdir - return testdir - -def removepy(name): - if name.endswith(os.extsep + "py"): - name = name[:-3] - return name +def findtestdir(path=None): + return path or os.path.dirname(__file__) or os.curdir + +def removepy(names): + if not names: + return + for idx, name in enumerate(names): + basename, ext = os.path.splitext(name) + if ext == '.py': + names[idx] = basename def count(n, word): if n == 1: @@ -1083,7 +1077,7 @@ from textwrap import fill blanks = ' ' * indent - print fill(' '.join(map(str, x)), width, + print fill(' '.join(str(elt) for elt in x), width, initial_indent=blanks, subsequent_indent=blanks) # Map sys.platform to a string containing the basenames of tests @@ -1510,24 +1504,8 @@ 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 = len(sys.path) - while i >= 0: - i -= 1 - if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: - del sys.path[i] - - # findtestdir() gets the dirname out of sys.argv[0], so we have to make it - # absolute before changing the CWD. - if sys.argv[0]: - sys.argv[0] = os.path.abspath(sys.argv[0]) - + # Simplification for findtestdir(). + assert __file__ == os.path.abspath(sys.argv[0]) # Define a writable temp dir that will be used as cwd while running # the tests. The name of the dir includes the pid to allow parallel