Merge pull request #2610 from AgriConnect/doctest-lineno

Report lineno from doctest
This commit is contained in:
Bruno Oliveira 2017-07-24 16:29:02 -03:00 committed by GitHub
commit 70d9f8638f
3 changed files with 18 additions and 1 deletions

View File

@ -140,7 +140,7 @@ class DoctestItem(pytest.Item):
return super(DoctestItem, self).repr_failure(excinfo) return super(DoctestItem, self).repr_failure(excinfo)
def reportinfo(self): 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(): def _get_flag_lookup():

1
changelog/2610.bugfix Normal file
View File

@ -0,0 +1 @@
doctests line numbers are now reported correctly, fixing `pytest-sugar#122 <https://github.com/Frozenball/pytest-sugar/issues/122>`_.

View File

@ -545,6 +545,22 @@ class TestDoctests(object):
result = testdir.runpytest(p, '--doctest-modules') result = testdir.runpytest(p, '--doctest-modules')
result.stdout.fnmatch_lines(['* 1 passed *']) 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): class TestLiterals(object):