This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "python -m doctest" results in FAIL: Doctest: __main__.DebugRunner
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: belopolsky, flox, r.david.murray
Priority: low Keywords: patch

Created on 2009-11-22 17:57 by flox, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue7376.diff belopolsky, 2009-11-23 04:19 Patch against revision 76221
issue7376_usage.diff flox, 2009-12-20 10:36 Patch, apply to trunk and py3k
issue7376_usage_v2.diff flox, 2009-12-20 16:36 Patch, apply to trunk and py3k
Messages (11)
msg95605 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-11-22 17:57
Running on Debian Lenny, with Python 3.1.
The Python 2.5 version is OK.

~ $ python3 --version
Python 3.1.1+
~ $ python3 -m doctest
F..............
======================================================================
FAIL: Doctest: __main__.DebugRunner
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.1/doctest.py", line 2096, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for __main__.DebugRunner
  File "/usr/lib/python3.1/doctest.py", line 1644, in DebugRunner

----------------------------------------------------------------------
File "/usr/lib/python3.1/doctest.py", line 1712, in __main__.DebugRunner
Failed example:
    runner.run(test)
Expected:
    Traceback (most recent call last):
    ...
    doctest.UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
Got:
    Traceback (most recent call last):
      File "/usr/lib/python3.1/doctest.py", line 1243, in __run
        compileflags, 1), test.globs)
      File "<doctest __main__.DebugRunner[15]>", line 1, in <module>
        runner.run(test)
      File "/usr/lib/python3.1/doctest.py", line 1736, in run
        r = DocTestRunner.run(self, test, compileflags, out, False)
      File "/usr/lib/python3.1/doctest.py", line 1375, in run
        return self.__run(test, compileflags, out)
      File "/usr/lib/python3.1/doctest.py", line 1296, in __run
        exception)
      File "/usr/lib/python3.1/doctest.py", line 1742, in
report_unexpected_exception
        raise UnexpectedException(test, example, exc_info)
    UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>


----------------------------------------------------------------------
Ran 15 tests in 0.015s

FAILED (failures=1)
~ $
msg95613 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2009-11-23 04:19
Apparently this was introduced with r51625 :

r51625 | guido.van.rossum | 2006-08-26 16:37:44 -0400 (Sat, 26 Aug 2006) 
| 4 lines

Inspired by SF patch #860326, make the exception formatting by
traceback.py be closer to the built-in formatting.
A few unittests had to be fixed, too.

------------------------------------------------------------------------


When doctest is imported as __main__, traceback does not prepend 
UnexpectedException with doctest. prefix.  Attached patch fixes the 
issue by explicitly reimporting doctest in the 'if __name__ == 
"__main__":' clause.

This is rather inelegant and a better solution would probably be to use 
python -m doctest for something other than self test.  For example, 
running doctest.testfile on command line arguments would be a reasonable  
use, but python -m doctest Lib/doctest.py may still have a problem.
msg95618 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-11-23 10:32
python -m doctest does accept file arguments.  Running the self-test is
the default if no arguments are supplied.

python -m doctest Lib/doctest.py passes.

So perhaps we should just remove the default and instead issue an error
message about missing arguments.
msg95628 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-11-23 13:57
I am ok with the proposal of removing the current "selftest" default
behavior.

And thank you for the tip.
I tried the command "python -m doctest Lib/*.py" and I found interesting
things:
 * #7379 about Lib/fractions.py
 * #7380 about Lib/uuid.py
 * #7381 about Lib/subprocess.py

;)
msg95647 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-11-23 19:14
Patch proposed.
msg95653 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-11-23 20:10
Patch could be applied to Python 2.6 and trunk too.
msg96671 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-20 10:36
Minor update: replaced '{}' by '{0}' for compatibility with 2.6.

Ready for review and merge.
msg96686 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-12-20 14:51
The patch results in this type of usage message:

usage: /home/rdmurray/python/trunk/Lib/doctest.py [-v] file ...

which while technically correct isn't the way I called it.  It would be
better to at least use basename on argv[0].  (I wonder if there's some
way for a module to know it was called via -m...).
msg96694 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-20 16:36
Variant which gives different usage messages:

~ $ ./python -m doctest
usage: doctest [-v] file ...

~ $ ./python Lib/doctest.py
usage: Lib/doctest.py [-v] file ...
msg96696 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-12-20 16:48
I has already adjusted the patch, in a slightly different fashion, but
to much the same effect.  Checked in to trunk in r76935.
msg96700 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-12-20 17:38
The bug doesn't exist on 2.6, so I'm not backporting.  Ported to py3k in
r76937 and backported to 3.1 in r76938.
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51625
2009-12-20 17:38:31r.david.murraysetstatus: open -> closed
versions: - Python 2.6
messages: + msg96700

resolution: fixed
stage: commit review -> resolved
2009-12-20 16:48:34r.david.murraysetmessages: + msg96696
2009-12-20 16:36:48floxsetfiles: + issue7376_usage_v2.diff

messages: + msg96694
2009-12-20 14:51:24r.david.murraysetmessages: + msg96686
2009-12-20 14:26:39r.david.murraysetstage: patch review -> commit review
2009-12-20 14:26:16r.david.murraysetassignee: r.david.murray
2009-12-20 10:36:48floxsetstage: patch review
2009-12-20 10:36:03floxsetfiles: + issue7376_usage.diff

messages: + msg96671
2009-12-20 10:33:12floxsetfiles: - issue7376_usage.diff
2009-11-23 20:10:10floxsetmessages: + msg95653
versions: + Python 2.6, Python 2.7
2009-11-23 19:18:45floxsetfiles: - issue7376_usage.diff
2009-11-23 19:18:35floxsetfiles: + issue7376_usage.diff
2009-11-23 19:14:20floxsetfiles: + issue7376_usage.diff

messages: + msg95647
2009-11-23 13:57:24floxsetmessages: + msg95628
2009-11-23 10:33:39r.david.murraysettitle: FAIL: Doctest: __main__.DebugRunner -> "python -m doctest" results in FAIL: Doctest: __main__.DebugRunner
2009-11-23 10:32:34r.david.murraysetpriority: low

nosy: + r.david.murray
messages: + msg95618

type: behavior
2009-11-23 04:19:02belopolskysetfiles: + issue7376.diff

nosy: + belopolsky
messages: + msg95613

keywords: + patch
2009-11-22 17:57:12floxcreate