Skip to content

Commit 572205d

Browse files
ogriselKartik Raj
authored andcommitted
Fix test discovery crash in pytest adapter on doctest (lineno is None) (#8920)
* FIX better handle unknown lineno in pytest discovery * Add changelog entry * Trigger CI to check potentially unrelated Heisen-failure
1 parent 581cc77 commit 572205d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

news/2 Fixes/7487.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash when using pytest to discover doctests with unknown line number.
2+
(thanks [Olivier Grisel](https://github.com/ogrisel/))

pythonFiles/testing_tools/adapter/pytest/_pytest_item.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,16 @@ def _get_location(item, testroot, relfile, #*,
274274
# function to be in relfile. So here we ignore any
275275
# other file and just say "somewhere in relfile".
276276
lineno = None
277-
if lineno is None:
278-
lineno = -1 # i.e. "unknown"
279277
elif _matches_relfile(srcfile, testroot, relfile):
280278
srcfile = relfile
281279
# Otherwise we just return the info from item.location as-is.
282280

283281
if not srcfile.startswith('.' + _pathsep):
284282
srcfile = '.' + _pathsep + srcfile
283+
284+
if lineno is None:
285+
lineno = -1 # i.e. "unknown"
286+
285287
# from pytest, line numbers are 0-based
286288
location = '{}:{}'.format(srcfile, int(lineno) + 1)
287289
return location, fullname

0 commit comments

Comments
 (0)