diff options
author | Nikolay Kondratyev <kondratyev.nv@gmail.com> | 2019-10-28 00:28:21 +0300 |
---|---|---|
committer | Nikolay Kondratyev <kondratyev.nv@gmail.com> | 2019-11-22 23:50:20 +0300 |
commit | 5e097970df24a47a5944f29a6dca1eb1219b5b8e (patch) | |
tree | 23109efa7a9efb981b9912b5c428e662cbbc2254 /testing | |
parent | 0601f5cdad56a3e64cf15618ee2856a49aab58cd (diff) | |
download | pytest-5e097970df24a47a5944f29a6dca1eb1219b5b8e.tar.gz |
Fix line detection for properties in doctest tests
Co-Authored-By: Daniel Hahler <github@thequod.de>
Diffstat (limited to 'testing')
-rw-r--r-- | testing/test_doctest.py | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 79095e3e7..bd214e3de 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -288,12 +288,67 @@ class TestDoctests: ) result = testdir.runpytest("--doctest-modules") result.stdout.fnmatch_lines( + ["*hello*", "006*>>> 1/0*", "*UNEXPECTED*ZeroDivision*", "*1 failed*"] + ) + + def test_doctest_linedata_on_property(self, testdir): + testdir.makepyfile( + """ + class Sample(object): + @property + def some_property(self): + ''' + >>> Sample().some_property + 'another thing' + ''' + return 'something' + """ + ) + result = testdir.runpytest("--doctest-modules") + result.stdout.fnmatch_lines( [ - "*hello*", - "*EXAMPLE LOCATION UNKNOWN, not showing all tests of that example*", - "*1/0*", - "*UNEXPECTED*ZeroDivision*", - "*1 failed*", + "*= FAILURES =*", + "*_ [[]doctest[]] test_doctest_linedata_on_property.Sample.some_property _*", + "004 ", + "005 >>> Sample().some_property", + "Expected:", + " 'another thing'", + "Got:", + " 'something'", + "", + "*/test_doctest_linedata_on_property.py:5: DocTestFailure", + "*= 1 failed in *", + ] + ) + + def test_doctest_no_linedata_on_overriden_property(self, testdir): + testdir.makepyfile( + """ + class Sample(object): + @property + def some_property(self): + ''' + >>> Sample().some_property + 'another thing' + ''' + return 'something' + some_property = property(some_property.__get__, None, None, some_property.__doc__) + """ + ) + result = testdir.runpytest("--doctest-modules") + result.stdout.fnmatch_lines( + [ + "*= FAILURES =*", + "*_ [[]doctest[]] test_doctest_no_linedata_on_overriden_property.Sample.some_property _*", + "EXAMPLE LOCATION UNKNOWN, not showing all tests of that example", + "[?][?][?] >>> Sample().some_property", + "Expected:", + " 'another thing'", + "Got:", + " 'something'", + "", + "*/test_doctest_no_linedata_on_overriden_property.py:None: DocTestFailure", + "*= 1 failed in *", ] ) |