Skip to content

Commit a189b01

Browse files
committed
conftest: add pytest hook to make test results visible from fixtures
Comes from official pytest examples, with included example: https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures Signed-off-by: Yann Dirson <[email protected]>
1 parent c9a596f commit a189b01

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ def pytest_collection_modifyitems(items, config):
108108
# multi_vms implies small_vm
109109
item.add_marker('small_vm')
110110

111+
# BEGIN make test results visible from fixtures
112+
# from https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
113+
114+
# FIXME we may have to move this into lib/ if fixtures in sub-packages
115+
# want to make use of this feature
116+
from pytest import StashKey, CollectReport
117+
PHASE_REPORT_KEY = StashKey[dict[str, CollectReport]]()
118+
119+
@pytest.hookimpl(wrapper=True, tryfirst=True)
120+
def pytest_runtest_makereport(item, call):
121+
# execute all other hooks to obtain the report object
122+
rep = yield
123+
124+
# store test results for each phase of a call, which can
125+
# be "setup", "call", "teardown"
126+
item.stash.setdefault(PHASE_REPORT_KEY, {})[rep.when] = rep
127+
128+
return rep
129+
130+
# END make test results visible from fixtures
131+
132+
111133
### fixtures
112134

113135
def setup_host(hostname_or_ip):

0 commit comments

Comments
 (0)