summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorThomas Hisch <t.hisch@gmail.com>2017-10-29 19:37:01 +0000
committerThomas Hisch <t.hisch@gmail.com>2017-10-29 20:06:10 +0000
commit2f993af54a1401460cc0f70915f28251f007344d (patch)
tree881739417b1caba906841d2bc6892eb908ff495a /testing
parent111d640bdb69a0bba25f86e5c265ab02415698c3 (diff)
downloadpytest-2f993af54a1401460cc0f70915f28251f007344d.tar.gz
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.
Diffstat (limited to 'testing')
-rw-r--r--testing/test_doctest.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/testing/test_doctest.py b/testing/test_doctest.py
index 8a81ea0ed..6616d2eae 100644
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -173,7 +173,7 @@ class TestDoctests(object):
"*UNEXPECTED*ZeroDivision*",
])
- def test_docstring_context_around_error(self, testdir):
+ def test_docstring_partial_context_around_error(self, testdir):
"""Test that we show some context before the actual line of a failing
doctest.
"""
@@ -199,7 +199,7 @@ class TestDoctests(object):
''')
result = testdir.runpytest('--doctest-modules')
result.stdout.fnmatch_lines([
- '*docstring_context_around_error*',
+ '*docstring_partial_context_around_error*',
'005*text-line-3',
'006*text-line-4',
'013*text-line-11',
@@ -213,6 +213,32 @@ class TestDoctests(object):
assert 'text-line-2' not in result.stdout.str()
assert 'text-line-after' not in result.stdout.str()
+ def test_docstring_full_context_around_error(self, testdir):
+ """Test that we show the whole context before the actual line of a failing
+ doctest, provided that the context is up to 10 lines long.
+ """
+ testdir.makepyfile('''
+ def foo():
+ """
+ text-line-1
+ text-line-2
+
+ >>> 1 + 1
+ 3
+ """
+ ''')
+ result = testdir.runpytest('--doctest-modules')
+ result.stdout.fnmatch_lines([
+ '*docstring_full_context_around_error*',
+ '003*text-line-1',
+ '004*text-line-2',
+ '006*>>> 1 + 1',
+ 'Expected:',
+ ' 3',
+ 'Got:',
+ ' 2',
+ ])
+
def test_doctest_linedata_missing(self, testdir):
testdir.tmpdir.join('hello.py').write(_pytest._code.Source("""
class Fun(object):