blob: 72e0359f045f2e27586baed5c2ee84a75d8fab3d [file] [log] [blame]
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02001from fixtures.base import *
Hanna Arhipova56eab942019-05-06 20:14:18 +03002import logging
Hanna Arhipova8c05e272019-04-24 11:47:31 +03003
4
5@pytest.hookimpl(tryfirst=True, hookwrapper=True)
6def pytest_runtest_makereport(item, call):
7 outcome = yield
8
9 rep = outcome.get_result()
10 setattr(item, "rep_" + rep.when, rep)
11 rep.description = "{}".format(str(item.function.__doc__))
12 setattr(item, 'description', item.function.__doc__)
13
14
15@pytest.fixture(autouse=True)
16def show_test_steps(request):
17 yield
18 # request.node is an "item" because we use the default
19 # "function" scope
20 if request.node.description is None or request.node.description == "None":
21 return
22 try:
23 if request.node.rep_setup.failed:
Hanna Arhipova56eab942019-05-06 20:14:18 +030024 logging.warning("setup failed. The following steps were attempted: \n {steps}".format(steps=request.node.description))
Hanna Arhipova8c05e272019-04-24 11:47:31 +030025 elif request.node.rep_setup.passed:
26 if request.node.rep_call.failed:
Hanna Arhipova56eab942019-05-06 20:14:18 +030027 logging.warning("test execution failed! The following steps were attempted: \n {steps}".format(steps=request.node.description))
Hanna Arhipova8c05e272019-04-24 11:47:31 +030028 except BaseException as e:
Hanna Arhipova56eab942019-05-06 20:14:18 +030029 logging.info("Error in show_test_steps fixture: {}".format(e))
Hanna Arhipova8c05e272019-04-24 11:47:31 +030030 pass