Repository navigation
Replies: 1 comment
|
Hi @tcpdcp22 The important distinction is between running a test phase and creating the report for that phase. Pytest executes three phases: and each phase receives its own
If you need the result, use: pytest_runtest_makereportFor current-style pluggy wrappers: import pytest
@pytest.hookimpl(wrapper=True)
def pytest_runtest_makereport(item, call):
report = yield
if report.when == "call":
if report.passed:
print("test passed")
elif report.failed:
print("test failed")
elif report.skipped:
print("test skipped")
return reportFor the older @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
if report.when == "call":
print(report.outcome)That also explains why you can see: Those are not contradictory. For example: @pytest.fixture
def resource():
yield
raise RuntimeError("cleanup failed")
def test_example(resource):
assert TrueThe test body succeeds: but fixture cleanup fails later: Pytest therefore reports the overall test run with a teardown error even though the actual test function passed. Finally, code such as: return (yield)in a wrapper simply forwards the result produced by the wrapped hook implementation unchanged. So if your objective is to inspect pass/fail/skip state, Please mark this answer as accepted if it helped, thank you. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello.
I use pytest 8.2.2
Could you please explain:
if i write
in 'res' I don't see the test status, why? After all, logically, these hooks call the next tests or a teardown for a test and already know about the result of the completed test.
return(yield)?All reactions