@@ -173,7 +173,7 @@ def test_doctest_unexpected_exception(self, testdir):
173173 "*UNEXPECTED*ZeroDivision*" ,
174174 ])
175175
176- def test_docstring_context_around_error (self , testdir ):
176+ def test_docstring_partial_context_around_error (self , testdir ):
177177 """Test that we show some context before the actual line of a failing
178178 doctest.
179179 """
@@ -199,7 +199,7 @@ def foo():
199199 ''' )
200200 result = testdir .runpytest ('--doctest-modules' )
201201 result .stdout .fnmatch_lines ([
202- '*docstring_context_around_error *' ,
202+ '*docstring_partial_context_around_error *' ,
203203 '005*text-line-3' ,
204204 '006*text-line-4' ,
205205 '013*text-line-11' ,
@@ -213,6 +213,33 @@ def foo():
213213 assert 'text-line-2' not in result .stdout .str ()
214214 assert 'text-line-after' not in result .stdout .str ()
215215
216+ def test_docstring_full_context_around_error (self , testdir ):
217+ """Test that we show the whole context before the actual line of a failing
218+ doctest, provided that the context is up to 10 lines long.
219+ """
220+ testdir .makepyfile ('''
221+ def foo():
222+ """
223+ text-line-1
224+ text-line-2
225+
226+ >>> 1 + 1
227+ 3
228+ """
229+ ''' )
230+ result = testdir .runpytest ('--doctest-modules' )
231+ raise ValueError
232+ result .stdout .fnmatch_lines ([
233+ '*docstring_full_context_around_error*' ,
234+ '003*text-line-1' ,
235+ '004*text-line-2' ,
236+ '006*>>> 1 + 1' ,
237+ 'Expected:' ,
238+ ' 3' ,
239+ 'Got:' ,
240+ ' 2' ,
241+ ])
242+
216243 def test_doctest_linedata_missing (self , testdir ):
217244 testdir .tmpdir .join ('hello.py' ).write (_pytest ._code .Source ("""
218245 class Fun(object):
0 commit comments