summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2017-07-24 16:29:02 -0300
committerGitHub <noreply@github.com>2017-07-24 16:29:02 -0300
commit70d9f8638f95a8b4808f3ba6523cbce31db0c6c9 (patch)
tree92a86bcdd06fb3ad169a67de0e25c4adcc6e1742
parente44284c1257495402ee94e79302ee54fc94552b7 (diff)
parentd40d77432c71d8eaa6bbc1dfb908fbcd4fe2bbb1 (diff)
downloadpytest-70d9f8638f95a8b4808f3ba6523cbce31db0c6c9.tar.gz
Merge pull request #2610 from AgriConnect/doctest-lineno
Report lineno from doctest
-rw-r--r--_pytest/doctest.py2
-rw-r--r--changelog/2610.bugfix1
-rw-r--r--testing/test_doctest.py16
3 files changed, 18 insertions, 1 deletions
diff --git a/_pytest/doctest.py b/_pytest/doctest.py
index 88174cc72..cc505c8d0 100644
--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -140,7 +140,7 @@ class DoctestItem(pytest.Item):
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():
diff --git a/changelog/2610.bugfix b/changelog/2610.bugfix
new file mode 100644
index 000000000..3757723e0
--- /dev/null
+++ b/changelog/2610.bugfix
@@ -0,0 +1 @@
+doctests line numbers are now reported correctly, fixing `pytest-sugar#122 <https://github.com/Frozenball/pytest-sugar/issues/122>`_.
diff --git a/testing/test_doctest.py b/testing/test_doctest.py
index dd444569c..8a81ea0ed 100644
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -545,6 +545,22 @@ class TestDoctests(object):
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):