pytest_runtest_makereport() gets two arguments, item and call. From item, I can find the funcarg I created for this test, and from call, I can find the exception info (if any):
While hpk42's answer works, __multicall__
is being depreciated.
This achieves the same result though:
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
return rep
There is a little undocumented somewhat unofficial method with which hook implementations can interact with other hook implementations, for example to post-process their result. In your concrete case you might do something like:
@pytest.mark.tryfirst
def pytest_runtest_makereport(item, call, __multicall__):
rep = __multicall__.execute()
# your code follows and you can use rep.passed etc.
return rep
Notes:
The multicall API is very seldomly really and i suspect there could be solutions for your use case that don't require it.
HTH, Holger