@@ -895,29 +895,30 @@ here is a little example implemented via a local plugin:
895
895
896
896
import pytest
897
897
898
+ phase_report_key = StashKey[Dict[str , CollectReport]]()
899
+
898
900
899
901
@pytest.hookimpl (tryfirst = True , hookwrapper = True )
900
902
def pytest_runtest_makereport (item , call ):
901
903
# execute all other hooks to obtain the report object
902
904
outcome = yield
903
905
rep = outcome.get_result()
904
906
905
- # set a report attribute for each phase of a call, which can
907
+ # store test results for each phase of a call, which can
906
908
# be "setup", "call", "teardown"
907
-
908
- setattr (item, " rep_" + rep.when, rep)
909
+ item.stash.setdefault(phase_report_key, {})[rep.when] = rep
909
910
910
911
911
912
@pytest.fixture
912
913
def something (request ):
913
914
yield
914
915
# request.node is an "item" because we use the default
915
916
# "function" scope
916
- if request.node.rep_setup.failed:
917
- print ( " setting up a test failed! " , request.node.nodeid)
918
- elif request.node.rep_setup.passed:
919
- if request.node.rep_call .failed:
920
- print (" executing test failed" , request.node.nodeid)
917
+ report = request.node.stash[phase_report_key]
918
+ if report[ " setup " ].failed:
919
+ print ( " setting up a test failed or skipped " , request.node.nodeid)
920
+ elif ( " call " not in report) or report[ " call " ] .failed:
921
+ print (" executing test failed or skipped " , request.node.nodeid)
921
922
922
923
923
924
if you then have failing tests:
0 commit comments