diff options
author | Daniel Hahler <git@thequod.de> | 2020-03-04 05:33:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-04 05:33:50 +0100 |
commit | acec0b688f542ac5c80c4e703e916595cca07c64 (patch) | |
tree | cb1de167d9d51ea45f01df483611eeab096899ae /testing/test_pytester.py | |
parent | 197b7c3bce2035fad7bba984ee353a51d9d0cde9 (diff) | |
download | pytest-acec0b688f542ac5c80c4e703e916595cca07c64.tar.gz |
Fix usage of pytester with doctests (#6802)
Use `request.node.name` instead of `request.function.__name__`:
`request.function` is `None` with `DoctestItem`s.
Diffstat (limited to 'testing/test_pytester.py')
-rw-r--r-- | testing/test_pytester.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/testing/test_pytester.py b/testing/test_pytester.py index a15ce1813..959000061 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -89,6 +89,29 @@ def test_testdir_runs_with_plugin(testdir) -> None: result.assert_outcomes(passed=1) +def test_testdir_with_doctest(testdir): + """Check that testdir can be used within doctests. + + It used to use `request.function`, which is `None` with doctests.""" + testdir.makepyfile( + **{ + "sub/t-doctest.py": """ + ''' + >>> import os + >>> testdir = getfixture("testdir") + >>> str(testdir.makepyfile("content")).replace(os.sep, '/') + '.../basetemp/sub.t-doctest0/sub.py' + ''' + """, + "sub/__init__.py": "", + } + ) + result = testdir.runpytest( + "-p", "pytester", "--doctest-modules", "sub/t-doctest.py" + ) + assert result.ret == 0 + + def test_runresult_assertion_on_xfail(testdir) -> None: testdir.makepyfile( """ |