From af2c15332422421ac280f90ac9a7ab470c44ed7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Mon, 24 Jul 2017 11:52:24 +0700 Subject: [PATCH 1/3] Report lineno from doctest This is to fix pytest-sugar#122 issue. --- _pytest/doctest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(): From dea671f8ba3a76283735e8414a11595bc755872d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Mon, 24 Jul 2017 22:01:03 +0700 Subject: [PATCH 2/3] Add changelog for #2610 --- changelog/2610.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/2610.bugfix 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 `_. From d40d77432c71d8eaa6bbc1dfb908fbcd4fe2bbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Mon, 24 Jul 2017 23:07:45 +0700 Subject: [PATCH 3/3] Add test case for DoctestItem.reportinfo() --- testing/test_doctest.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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):