8000 gh-111159: Fix `doctest` output comparison for exceptions with notes by sobolevn · Pull Request #111160 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111159: Fix doctest output comparison for exceptions with notes #111160

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

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
One more test
  • Loading branch information
sobolevn committed Oct 21, 2023
commit a7daef0797dc6dcc05144475f308d65391065114
33 changes: 33 additions & 0 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,39 @@ def test_syntax_error_with_note(cls, multiline=False):
raise exc


def test_syntax_error_with_incorrect_note():
"""
>>> def f(x):
... r'''
... >>> exc = SyntaxError("error", ("x.py", 23, None, "bad syntax"))
... >>> exc.add_note('note1')
... >>> exc.add_note('note2')
... >>> raise exc
... Traceback (most recent call last):
... SyntaxError: error
... wrong note
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
>>> doctest.DocTestRunner(verbose=False).run(test)
... # doctest: +ELLIPSIS
**********************************************************************
File "...", line 6, in f
Failed example:
raise exc
Expected:
Traceback (most recent call last):
SyntaxError: error
wrong note
Got:
Traceback (most recent call last):
...
SyntaxError: error
note1
note2
TestResults(failed=1, attempted=...)
"""


def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(doctest))
tests.addTest(doctest.DocTestSuite())
Expand Down
0