Skip to content
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

Doctest gets line numbers wrongs with <> in name #48907

Closed
ncoghlan opened this issue Dec 14, 2008 · 6 comments
Closed

Doctest gets line numbers wrongs with <> in name #48907

ncoghlan opened this issue Dec 14, 2008 · 6 comments

Comments

@ncoghlan
Copy link
Contributor

BPO 4657
Nosy @ncoghlan, @abalkin, @bitdancer, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-11-22.12:45:37.477>
created_at = <Date 2008-12-14.08:21:25.341>
labels = []
title = 'Doctest gets line numbers wrongs with <> in name'
updated_at = <Date 2020-11-22.12:45:37.475>
user = 'https://github.com/ncoghlan'

bugs.python.org fields:

activity = <Date 2020-11-22.12:45:37.475>
actor = 'iritkatriel'
assignee = 'none'
closed = True
closed_date = <Date 2020-11-22.12:45:37.477>
closer = 'iritkatriel'
components = []
creation = <Date 2008-12-14.08:21:25.341>
creator = 'ncoghlan'
dependencies = []
files = []
hgrepos = []
issue_num = 4657
keywords = []
message_count = 6.0
messages = ['77777', '112135', '112153', '132705', '132725', '381614']
nosy_count = 4.0
nosy_names = ['ncoghlan', 'belopolsky', 'r.david.murray', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue4657'
versions = ['Python 2.7']

@ncoghlan
Copy link
Contributor Author

When writing the unit tests for running doctests from inside a zipfile,
I initially had "<anon>" as the name being passed to the
doctest.DocTestFinder.find method.

With that name, the line numbers coming back for all of the examples
were being incremented by 1 beyond what test_doctest expected (and hence
my tests were failing).

Changing the name to "anon" eliminated the errors. (Both "<anon" and
"anon>" also failed in the same fashion as "<anon>")

I suspect there may be a problem with __LINECACHE_FILENAME_RE when "<"
or ">" are embedded in the name used for the doctest execution.

@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jul 31, 2010

@nick: could you provide a patch that addresses this issue?

@ncoghlan
Copy link
Contributor Author

On Sat, Jul 31, 2010 at 9:30 PM, Mark Lawrence <report@bugs.python.org> wrote:

Mark Lawrence <breamoreboy@yahoo.co.uk> added the comment:

@nick: could you provide a patch that addresses this issue?

Probably, but the "don't do that" work around is trivial enough that
my own motivation to fix it is really low (otherwise I would have
fixed it by now).

It's still a genuine bug though. Since my original post isn't all that
helpful in reproducing it, I'll provide some more details for anyone
else that wants to tackle it.

To reproduce it, edit Lib/test/test_zipimport_support.py to pass
"<anon>" instead of name as the second argument to the finder.find
call inside _run_object_doctest(). Running "python -m test.regrtest
test_zipimport_support" will fail (with 6 of 33 doctests failing as of
2.7)

Then pass "anon" (no angle brackets) to see that the reported doctest
errors are different (1 of 19 reported as failing in 2.7) and, unlike
the errors with "<anon>" the error in this latter case is directly
attributable to having the wrong module name in the pdb output.

(Note: regrtest's "-v" option is actually more confusing than helpful
in debugging this test case due to the sheer amount of output it
generates from the doctest tests themselves)

@ncoghlan
Copy link
Contributor Author

Note that this appears to have been fixed already in the 3.x series (I haven't investigated the differences to see what makes this a 2.x only problem)

@bitdancer
Copy link
Member

I have a vague memory of changing some code, in linecache I think, that involved anonymous names. I might have fixed it by accident.

@iritkatriel
Copy link
Member

I tested on 3.10 (macos) and can confirm that it is fixed.

Details: I changed _run_object_doctest as Nick explained, and made it display the output of the finder.find() call - the line number was the same with and without the <>s.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants