Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"python -m doctest" results in FAIL: Doctest: __main__.DebugRunner #51625

Closed
florentx mannequin opened this issue Nov 22, 2009 · 11 comments
Closed

"python -m doctest" results in FAIL: Doctest: __main__.DebugRunner #51625

florentx mannequin opened this issue Nov 22, 2009 · 11 comments
Assignees
Labels
stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@florentx
Copy link
Mannequin

florentx mannequin commented Nov 22, 2009

BPO 7376
Nosy @abalkin, @bitdancer, @florentx
Files
  • issue7376.diff: Patch against revision 76221
  • issue7376_usage.diff: Patch, apply to trunk and py3k
  • issue7376_usage_v2.diff: Patch, apply to trunk and py3k
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/bitdancer'
    closed_at = <Date 2009-12-20.17:38:31.574>
    created_at = <Date 2009-11-22.17:57:12.268>
    labels = ['tests', 'type-bug', 'library']
    title = '"python -m doctest" results in FAIL: Doctest: __main__.DebugRunner'
    updated_at = <Date 2009-12-20.17:38:31.571>
    user = 'https://github.com/florentx'

    bugs.python.org fields:

    activity = <Date 2009-12-20.17:38:31.571>
    actor = 'r.david.murray'
    assignee = 'r.david.murray'
    closed = True
    closed_date = <Date 2009-12-20.17:38:31.574>
    closer = 'r.david.murray'
    components = ['Library (Lib)', 'Tests']
    creation = <Date 2009-11-22.17:57:12.268>
    creator = 'flox'
    dependencies = []
    files = ['15380', '15622', '15626']
    hgrepos = []
    issue_num = 7376
    keywords = ['patch']
    message_count = 11.0
    messages = ['95605', '95613', '95618', '95628', '95647', '95653', '96671', '96686', '96694', '96696', '96700']
    nosy_count = 3.0
    nosy_names = ['belopolsky', 'r.david.murray', 'flox']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue7376'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Nov 22, 2009

    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)
    ~ $

    @florentx florentx mannequin added stdlib Python modules in the Lib dir tests Tests in the Lib/test dir labels Nov 22, 2009
    @abalkin
    Copy link
    Member

    abalkin commented Nov 23, 2009

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

    @bitdancer
    Copy link
    Member

    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.

    @bitdancer bitdancer added the type-bug An unexpected behavior, bug, or error label Nov 23, 2009
    @bitdancer bitdancer changed the title FAIL: Doctest: __main__.DebugRunner "python -m doctest" results in FAIL: Doctest: __main__.DebugRunner Nov 23, 2009
    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Nov 23, 2009

    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:

    ;)

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Nov 23, 2009

    Patch proposed.

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Nov 23, 2009

    Patch could be applied to Python 2.6 and trunk too.

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Dec 20, 2009

    Minor update: replaced '{}' by '{0}' for compatibility with 2.6.

    Ready for review and merge.

    @bitdancer bitdancer self-assigned this Dec 20, 2009
    @bitdancer
    Copy link
    Member

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

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Dec 20, 2009

    Variant which gives different usage messages:

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

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

    @bitdancer
    Copy link
    Member

    I has already adjusted the patch, in a slightly different fashion, but
    to much the same effect. Checked in to trunk in r76935.

    @bitdancer
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants