Skip to content

Commit a0c0c9c

Browse files
Add a test for DocTestItem changes
1 parent 2a6bec1 commit a0c0c9c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

changelog/3806.improvement.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Implemented `pytest_runtest_teardown` hook in `_pytest/fixtures.py` to have high-scope fixtures torn-down at the last dependent test. Also moved initialization of `DoctestItem`'s `FixtureRequest` attribute from `DoctestItem.setup()` to its `__init__`, like `Function`.
1+
Implemented `pytest_runtest_teardown` hook in `_pytest/fixtures.py` to have high-scope fixtures torn-down at the last dependent test. Also moved initialization of `DoctestItem`'s `_request` attribute (of type `FixtureRequest`, renamed from `fixture_request`) from `DoctestItem.setup()` to its `__init__`, like `Function`.

testing/test_doctest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@
1818

1919

2020
class TestDoctests:
21+
def test_doctest_has__request(self, pytester: Pytester):
22+
txt_file = pytester.maketxtfile(
23+
"""
24+
>>> i = 2
25+
>>> i == 2
26+
True
27+
"""
28+
)
29+
items, _ = pytester.inline_genitems(txt_file)
30+
assert hasattr(items[0], "_request")
31+
assert type(items[0]._request).__name__ == "FixtureRequest"
32+
33+
py_file = pytester.makepyfile(
34+
'''
35+
def f():
36+
"""
37+
>>> 1 + 1
38+
2
39+
"""
40+
pass
41+
'''
42+
)
43+
items, _ = pytester.inline_genitems(py_file, "--doctest-modules")
44+
assert hasattr(items[0], "_request")
45+
assert type(items[0]._request).__name__ == "FixtureRequest"
46+
2147
def test_collect_testtextfile(self, pytester: Pytester):
2248
w = pytester.maketxtfile(whatever="")
2349
checkfile = pytester.maketxtfile(

0 commit comments

Comments
 (0)