diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-12-20 16:46:06 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-12-20 16:46:06 (GMT) |
commit | 77e48ba993a83ffd6e821ab69a09ab0d11771338 (patch) | |
tree | 699e1896c4c33348d9e4345dc11b7770de5efd62 /Lib/doctest.py | |
parent | 97138117b2a24c748dd2bd7e92843040700b0fd5 (diff) | |
download | cpython-77e48ba993a83ffd6e821ab69a09ab0d11771338.zip cpython-77e48ba993a83ffd6e821ab69a09ab0d11771338.tar.gz cpython-77e48ba993a83ffd6e821ab69a09ab0d11771338.tar.bz2 |
Issue #7376: When called with no arguments doctest was running a
self-test. Because of a change to the way tracebacks are printed,
this self-test was failing. The test is run (and passes) during normal
regression testing. So instead of running the failing self-test this
patch makes doctest emit a usage message. This is better behavior anyway
since passing in arguments is the real reason to run doctest as a command.
Bug discovery and initial patch by Florent Xicluna.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index aeeb15d..158e8b8 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -2660,27 +2660,31 @@ __test__ = {"_TestClass": _TestClass, """, } + def _test(): testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-'] - if testfiles: - for filename in testfiles: - if filename.endswith(".py"): - # It is a module -- insert its dir into sys.path and try to - # import it. If it is part of a package, that possibly won't work - # because of package imports. - dirname, filename = os.path.split(filename) - sys.path.insert(0, dirname) - m = __import__(filename[:-3]) - del sys.path[0] - failures, _ = testmod(m) - else: - failures, _ = testfile(filename, module_relative=False) - if failures: - return 1 - else: - r = unittest.TextTestRunner() - r.run(DocTestSuite()) + if not testfiles: + name = os.path.basename(sys.argv[0]) + if '__loader__' in globals() and name.endswith('.py'): # python -m + name, _ = os.path.splitext(name) + print("usage: {0} [-v] file ...".format(name)) + return 2 + for filename in testfiles: + if filename.endswith(".py"): + # It is a module -- insert its dir into sys.path and try to + # import it. If it is part of a package, that possibly + # won't work because of package imports. + dirname, filename = os.path.split(filename) + sys.path.insert(0, dirname) + m = __import__(filename[:-3]) + del sys.path[0] + failures, _ = testmod(m) + else: + failures, _ = testfile(filename, module_relative=False) + if failures: + return 1 return 0 + if __name__ == "__main__": sys.exit(_test()) |