tests: Handle pytest test state properly
- Log information about test fail in case of exception. - Skip teardown in case of test skip (setup is skipped by default). Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
9b17135694
commit
116d13364b
@ -84,11 +84,29 @@ def pytest_runtest_setup(item):
|
||||
TestRun.LOGGER.start_group("Test body")
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_makereport(item, call):
|
||||
res = (yield).get_result()
|
||||
|
||||
TestRun.outcome = res.outcome
|
||||
|
||||
from _pytest.outcomes import Failed
|
||||
if res.when == "call" and res.failed:
|
||||
msg = f"{call.excinfo.type.__name__}: {call.excinfo.value}"
|
||||
if call.excinfo.type is Failed:
|
||||
TestRun.LOGGER.error(msg)
|
||||
else:
|
||||
TestRun.LOGGER.exception(msg)
|
||||
|
||||
|
||||
def pytest_runtest_teardown():
|
||||
"""
|
||||
This method is executed always in the end of each test, even if it fails or raises exception in
|
||||
prepare stage.
|
||||
"""
|
||||
if TestRun.outcome == "skipped":
|
||||
return
|
||||
|
||||
TestRun.LOGGER.end_all_groups()
|
||||
|
||||
with TestRun.LOGGER.step("Cleanup after test"):
|
||||
|
Loading…
Reference in New Issue
Block a user