Skip to content

Commit

Permalink
Merge pull request #2610 from AgriConnect/doctest-lineno
Browse files Browse the repository at this point in the history
Report lineno from doctest
  • Loading branch information
nicoddemus authored Jul 24, 2017
2 parents e44284c + d40d774 commit 70d9f86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def repr_failure(self, excinfo):
return super(DoctestItem, self).repr_failure(excinfo)

def reportinfo(self):
return self.fspath, None, "[doctest] %s" % self.name
return self.fspath, self.dtest.lineno, "[doctest] %s" % self.name


def _get_flag_lookup():
Expand Down
1 change: 1 addition & 0 deletions changelog/2610.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doctests line numbers are now reported correctly, fixing `pytest-sugar#122 <https://github.com/Frozenball/pytest-sugar/issues/122>`_.
16 changes: 16 additions & 0 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,22 @@ def fix_bad_unicode(text):
result = testdir.runpytest(p, '--doctest-modules')
result.stdout.fnmatch_lines(['* 1 passed *'])

def test_reportinfo(self, testdir):
'''
Test case to make sure that DoctestItem.reportinfo() returns lineno.
'''
p = testdir.makepyfile(test_reportinfo="""
def foo(x):
'''
>>> foo('a')
'b'
'''
return 'c'
""")
items, reprec = testdir.inline_genitems(p, '--doctest-modules')
reportinfo = items[0].reportinfo()
assert reportinfo[1] == 1


class TestLiterals(object):

Expand Down

0 comments on commit 70d9f86

Please sign in to comment.