Skip to content

Commit

Permalink
Fix test discovery crash in pytest adapter on doctest (lineno is None) (
Browse files Browse the repository at this point in the history
microsoft#8920)

* FIX better handle unknown lineno in pytest discovery

* Add changelog entry

* Trigger CI to check potentially unrelated Heisen-failure
  • Loading branch information
ogrisel authored and Kartik Raj committed Dec 13, 2019
1 parent 581cc77 commit 572205d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions news/2 Fixes/7487.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash when using pytest to discover doctests with unknown line number.
(thanks [Olivier Grisel](https://github.com/ogrisel/))
6 changes: 4 additions & 2 deletions pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,16 @@ def _get_location(item, testroot, relfile, #*,
# function to be in relfile. So here we ignore any
# other file and just say "somewhere in relfile".
lineno = None
if lineno is None:
lineno = -1 # i.e. "unknown"
elif _matches_relfile(srcfile, testroot, relfile):
srcfile = relfile
# Otherwise we just return the info from item.location as-is.

if not srcfile.startswith('.' + _pathsep):
srcfile = '.' + _pathsep + srcfile

if lineno is None:
lineno = -1 # i.e. "unknown"

# from pytest, line numbers are 0-based
location = '{}:{}'.format(srcfile, int(lineno) + 1)
return location, fullname
Expand Down

0 comments on commit 572205d

Please sign in to comment.