testing - Detect whether test has failed within fixture -
i debugging intermittent test failure. purposes want dump lot of debug information if test failed. dumping debug stuff quite slow process produces lot of data, not want every test.
i using pytest , yield autouse fixture should work great
@pytest.yield_fixture(scope="function", autouse=true) def dump_on_failue(request): prepare_debug_dump() yield if test_failed(request): debug_dump()
the problem can't figure out how detect whether test has failed or not. there a questions already , note on pytest website:
if request.node.rep_setup.failed: print ("setting test failed!", request.node.nodeid) elif request.node.rep_setup.passed: if request.node.rep_call.failed: print ("executing test failed", request.node.nodeid)
unfortunately code not work anymore. there no rep_setup , rep_calls symbols in node object. tried dig request , node object, no luck.
anybody knows how detect whether test failed?
there no rep_setup , rep_calls symbols in node object.
no.rep_setup , rep_calls symbols still there.
add code root conftest.py
. check pass/fail every test function.
import pytest @pytest.mark.tryfirst def pytest_runtest_makereport(item, call, __multicall__): rep = __multicall__.execute() setattr(item, "rep_" + rep.when, rep) return rep @pytest.fixture(scope='function', autouse=true) def test_debug_log(request): def test_result(): if request.node.rep_setup.failed: print ("setting test failed!", request.node.nodeid) elif request.node.rep_setup.passed: if request.node.rep_call.failed: print ("executing test failed", request.node.nodeid) request.addfinalizer(test_result)
Comments
Post a Comment