Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 445448c

Browse files
committed
Merged revisions 76934-76935 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 1554b18 commit 445448c

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

Lib/doctest.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,27 +2611,31 @@ def get(self):
26112611
""",
26122612
}
26132613

2614+
26142615
def _test():
26152616
testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-']
2616-
if testfiles:
2617-
for filename in testfiles:
2618-
if filename.endswith(".py"):
2619-
# It is a module -- insert its dir into sys.path and try to
2620-
# import it. If it is part of a package, that possibly won't work
2621-
# because of package imports.
2622-
dirname, filename = os.path.split(filename)
2623-
sys.path.insert(0, dirname)
2624-
m = __import__(filename[:-3])
2625-
del sys.path[0]
2626-
failures, _ = testmod(m)
2627-
else:
2628-
failures, _ = testfile(filename, module_relative=False)
2629-
if failures:
2630-
return 1
2631-
else:
2632-
r = unittest.TextTestRunner()
2633-
r.run(DocTestSuite())
2617+
if not testfiles:
2618+
name = os.path.basename(sys.argv[0])
2619+
if '__loader__' in globals() and name.endswith('.py'): # python -m
2620+
name, _ = os.path.splitext(name)
2621+
print("usage: {0} [-v] file ...".format(name))
2622+
return 2
2623+
for filename in testfiles:
2624+
if filename.endswith(".py"):
2625+
# It is a module -- insert its dir into sys.path and try to
2626+
# import it. If it is part of a package, that possibly
2627+
# won't work because of package imports.
2628+
dirname, filename = os.path.split(filename)
2629+
sys.path.insert(0, dirname)
2630+
m = __import__(filename[:-3])
2631+
del sys.path[0]
2632+
failures, _ = testmod(m)
2633+
else:
2634+
failures, _ = testfile(filename, module_relative=False)
2635+
if failures:
2636+
return 1
26342637
return 0
26352638

2639+
26362640
if __name__ == "__main__":
26372641
sys.exit(_test())

Lib/runpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _run_module_as_main(mod_name, alter_argv=True):
125125
126126
Note that the executed module will have full access to the
127127
__main__ namespace. If this is not desirable, the run_module()
128-
function sbould be used to run the module code in a fresh namespace.
128+
function should be used to run the module code in a fresh namespace.
129129
130130
At the very least, these variables in __main__ will be overwritten:
131131
__name__

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ Documentation
511511
Tests
512512
-----
513513

514+
- Issue #7376: instead of running a self-test (which was failing) when called
515+
with no arguments, doctest.py now gives a usage message.
516+
514517
- Issue #7396: fix regrtest -s, which was broken by the -j enhancement.
515518

516519
- Issue #7498: test_multiprocessing now uses test.support.find_unused_port

0 commit comments

Comments
 (0)