]> granicus.if.org Git - python/commitdiff
Merged revisions 76934-76935 via svnmerge from
authorR. David Murray <rdmurray@bitdance.com>
Sun, 20 Dec 2009 17:28:31 +0000 (17:28 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Sun, 20 Dec 2009 17:28:31 +0000 (17:28 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76934 | r.david.murray | 2009-12-20 11:24:46 -0500 (Sun, 20 Dec 2009) | 2 lines

  Fix comment typo.
........
  r76935 | r.david.murray | 2009-12-20 11:46:06 -0500 (Sun, 20 Dec 2009) | 10 lines

  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.
........

Lib/doctest.py
Lib/runpy.py
Misc/NEWS

index b95566f6c68c01146c98920a45180cd05186ea72..9bae20f12181cc0854e2d21820c2297be17d8cc8 100644 (file)
@@ -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())
index 46e138e72479aa8585747980d3cdd9d4d5ba7c72..6e94d6bd752c7d11f978fdfbc0c502ae5c4cd5a2 100644 (file)
@@ -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__
index 226af736ccc01026fc78195849aed9d4a88d4dd9..f547cec8e6b3431cbadf018117718488664e5580 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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