Skip to content

Print traceback on DocTest Exception #43

Closed

Description

@pytestbot

Originally reported by: BitBucket: pasdavoine, GitHub: pasdavoine


Running a doctest with say :

#!python

>>> import foo

If some file in the import chain has an error (eg. importError) pytest will print :

UNEXPECTED EXCEPTION: ImportError('cannot import name bar',)

But I won't know where 'bar' is imported. I need the traceback.

So here is a patch in order for pytest to print the traceback. For example output would be :

#!python

016   >>> import foo
UNEXPECTED EXCEPTION: Traceback (most recent call last):

  File "/usr/lib/python2.6/doctest.py", line 1253, in __run
    compileflags, 1) in test.globs

  File "<doctest test_baz.txt[0]>", line 1, in <module>

  File "/path/to/code/foo/__init__.py", line 8, in <module>
    from baz import x

  File "/path/to/code/foo/baz.py", line 10, in <module>
    from bar import so_important

ImportError: No module named bar

Activity

  1. pytestbot commented on May 28, 2011

    @pytestbot
    ContributorAuthor

    Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


    fix issue43 - better tracebacks for unexpected exceptions in doctests

  2. added 2 commits that reference this issue on May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions