Fix context output handling for doctests

Show full context of doctest source in the pytest output, if the lineno of
failed example in the docstring is < 9.
This commit is contained in:
Thomas Hisch
2017-10-29 19:37:01 +00:00
parent 111d640bdb
commit 2f993af54a
3 changed files with 30 additions and 3 deletions
+1 -1
View File
@@ -120,7 +120,7 @@ class DoctestItem(pytest.Item):
lines = ["%03d %s" % (i + test.lineno + 1, x)
for (i, x) in enumerate(lines)]
# trim docstring error lines to 10
lines = lines[example.lineno - 9:example.lineno + 1]
lines = lines[max(example.lineno - 9, 0):example.lineno + 1]
else:
lines = ['EXAMPLE LOCATION UNKNOWN, not showing all tests of that example']
indent = '>>>'