Skip to content

Improved error reporting for doctests run with unittest #134857

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

There are several issues with error reports when doctests are wrapped in DocTestCase.

  • When error happens during compilation or execution an example, the traceback contains several lines from doctest.py:

        File ...
          exec(compile(example.source, filename, "single",
          ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                       compileflags, True), test.globs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
  • When the output differs, the traceback of AssertionError contains other line from doctest.py:

      Traceback (most recent call last):
        File ...
          raise self.failureException(self.format_failure(new.getvalue()))
    
  • Also, the AssertionError message contains redundant newline character.

Linked PRs

Metadata

Metadata

Labels

3.14bugs and security fixes3.15new features, bugs and security fixes

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions