Repository navigation
Closed
Description
Bug report
Minimal reproducer:
"""
Module doctest
>>> raise_with_note()
Traceback (most recent call last):
...
ValueError: Text
Note
"""
def raise_with_note():
err = ValueError('Text')
err.add_note('Note')
raise errNow, run it, you will get a very strange error:
» ./python.exe -m doctest ex.py
**********************************************************************
File "/Users/sobolev/Desktop/cpython/ex.py", line 4, in ex
Failed example:
raise_with_note()
Expected:
Traceback (most recent call last):
...
ValueError: Text
Note
Got:
Traceback (most recent call last):
File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run
exec(compile(example.source, filename, "single",
File "<doctest ex[0]>", line 1, in <module>
raise_with_note()
File "/Users/sobolev/Desktop/cpython/ex.py", line 14, in raise_with_note
raise err
ValueError: Text
Note
**********************************************************************
1 items had failures:
1 of 1 in ex
***Test Failed*** 1 failures.
Things that do not help:
IGNORE_EXCEPTION_DETAILELLIPSIS- Coping the whole traceback
Related to how exceptions with notes are represented in
Line 1396 in 7237fb5
| exc_msg = traceback.format_exception_only(*exception[:2])[-1] |
I am working on this issue right now :)
Refs #111157
Linked PRs
- gh-111159: Fix
doctestoutput comparison for exceptions with notes #111160 - [3.12] gh-111159: Fix
doctestoutput comparison for exceptions with notes (GH-111160) #111169 - [3.11] gh-111159: Fix
doctestoutput comparison for exceptions with notes (GH-111160) #111170 - gh-111159: Fix
SyntaxErrordoctests for non-builtin exception classes #111541 - [3.12] gh-111159: Fix
SyntaxErrordoctests for non-builtin exception classes (GH-111541) #111732 - [3.11] gh-111159: Fix
SyntaxErrordoctests for non-builtin exception classes (GH-111541) #111733
Activity
pythongh-111159: Fix `doctest` output comparison for exceptions with …
pythongh-111159: Fix `doctest` output comparison for exceptions with …
gh-111159: Fix `doctest` output comparison for exceptions with notes (#…
pythongh-111159: Fix `doctest` output comparison for exceptions with …
pythongh-111159: Fix `doctest` output comparison for exceptions with …
[3.11] gh-111159: Fix `doctest` output comparison for exceptions with…
[3.12] gh-111159: Fix `doctest` output comparison for exceptions with…
scoder commentedon Oct 31, 2023
With this change in place, I now get a (reproducible) doctest failure in lxml that seems rather random:
https://github.com/lxml/lxml/blob/7356acba91bcf37b2c1c6ab5b7c9e37a4f1145b9/doc/xpathxslt.txt
I'm not using "notes" anywhere in the file (and wouldn't know what I'd use them for), so this breaks existing tests.
sobolevn commentedon Oct 31, 2023
Thanks, I will have a look!
scoder commentedon Oct 31, 2023
I think the problem is with subclasses of
SyntaxError. If they live in packages, thestartswith()comparison in the newly added code can fail.pythongh-111159: Fix `SyntaxError` doctests for non-builtin exception…
gh-111159: Fix `SyntaxError` doctests for non-builtin exception class…
pythongh-111159: Fix `SyntaxError` doctests for non-builtin exception…
pythongh-111159: Fix `SyntaxError` doctests for non-builtin exception…
[3.11] gh-111159: Fix `SyntaxError` doctests for non-builtin exceptio…
[3.12] gh-111159: Fix `SyntaxError` doctests for non-builtin exceptio…
hugovk commentedon Nov 9, 2023
Anything left for this issue or can it be closed? Thanks!
pythongh-111159: Fix `doctest` output comparison for exceptions with …
pythongh-111159: Fix `SyntaxError` doctests for non-builtin exception…
pythongh-111159: Fix `doctest` output comparison for exceptions with …
pythongh-111159: Fix `SyntaxError` doctests for non-builtin exception…