-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Doctest incorrectly locates a decorated function #115392
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
Comments
I traced this bug down to inside Lines 1141 to 1163 in 4deb705
While processing the decorated function
This is actually purely accidental. It only works because in this case because |
@brianschubert Would the fix for this be to check if objects that are functions or methods are wrapped? There could be a check if the function has the attribute |
@boshea93 I was just writing the same. I think a possible fix would be to check for a |
…orated functions (pythonGH-115440) (cherry picked from commit bb791c7) Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
…orated functions (pythonGH-115440) (cherry picked from commit bb791c7) Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Thanks for the fix @brianschubert, and thanks for the report @chaudhary1337! |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
TL;DR: If a function is decorated, the doctest is unable to find the correct location of the function.
Example
Consider two simple files,
main.py
anddecorate.py
.Contents of
main.py
:Contents of
decorate.py
:If we run a doctest like so:
python3 -m doctest main.py
, we find the error correctly on the line number 7, the line which says>>> foo()
. Traceback is output as follows.Incorrect Output
However, if we move the
decorator
definition in thedecorate.py
file by a few lines, as shown, (the space between could be empty/defining a function, etc.), we see that the doctest is unable to find the location of the decorated function,foo
, and just outputs?
as the line number.Traceback:
PS: If move the
decorator
definition by even a line up, it shows that the line,>>> foo()
incorrectly lives on line 10 and not line 7.Why?
The "?" is printed simply because while doctest is able to find the example's lineno, it is unable to understand the test's lineno. I found this after printing out the line numbers in the
_failure_header
function indoctest.py
.CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: