Skip to content

Improved error reporting for doctests run with unittest #134857

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

Closed
serhiy-storchaka opened this issue May 28, 2025 · 1 comment
Closed

Improved error reporting for doctests run with unittest #134857

serhiy-storchaka opened this issue May 28, 2025 · 1 comment
Assignees
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented May 28, 2025

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

@serhiy-storchaka serhiy-storchaka self-assigned this May 28, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 28, 2025
Remove doctest module frames from tracebacks and redundand newline
character from a failure message.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue May 28, 2025
Remove doctest module frames from tracebacks and redundant newline
character from a failure message.
@serhiy-storchaka
Copy link
Member Author

@hugovk, this is borderline between a bug fix and a new feature. On one hand, the current behavior is wrong. On other hand, it was so from beginning, so some code can depend on exact output, although this is unlikely, because these details look wrong and unstable. So I think that this change can be backported to 3.14, but not to 3.13.

@serhiy-storchaka serhiy-storchaka added 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels May 28, 2025
serhiy-storchaka added a commit that referenced this issue May 29, 2025
…4858)

Remove doctest module frames from tracebacks and redundant newline
character from a failure message.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 29, 2025
…ythonGH-134858)

Remove doctest module frames from tracebacks and redundant newline
character from a failure message.
(cherry picked from commit cb8a72b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue May 30, 2025
…GH-134858) (GH-134903)

Remove doctest module frames from tracebacks and redundant newline
character from a failure message.
(cherry picked from commit cb8a72b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in Unittest issues May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes
Projects
Status: Done
Development

No branches or pull requests

1 participant