diff options
-rw-r--r-- | Lib/doctest.py | 40 | ||||
-rw-r--r-- | Lib/runpy.py | 2 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 26 insertions, 19 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index b95566f..9bae20f 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -2611,27 +2611,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()) diff --git a/Lib/runpy.py b/Lib/runpy.py index 46e138e..6e94d6b 100644 --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -125,7 +125,7 @@ def _run_module_as_main(mod_name, alter_argv=True): Note that the executed module will have full access to the __main__ namespace. If this is not desirable, the run_module() - function sbould be used to run the module code in a fresh namespace. + function should be used to run the module code in a fresh namespace. At the very least, these variables in __main__ will be overwritten: __name__ @@ -511,6 +511,9 @@ Documentation Tests ----- +- Issue #7376: instead of running a self-test (which was failing) when called + with no arguments, doctest.py now gives a usage message. + - Issue #7396: fix regrtest -s, which was broken by the -j enhancement. - Issue #7498: test_multiprocessing now uses test.support.find_unused_port |