blob: 72e0359f045f2e27586baed5c2ee84a75d8fab3d [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001from fixtures.base import *
Hanna Arhipova1eef8312019-05-06 20:14:18 +03002import logging
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +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 Arhipova1eef8312019-05-06 20:14:18 +030024 logging.warning("setup failed. The following steps were attempted: \n {steps}".format(steps=request.node.description))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030025 elif request.node.rep_setup.passed:
26 if request.node.rep_call.failed:
Hanna Arhipova1eef8312019-05-06 20:14:18 +030027 logging.warning("test execution failed! The following steps were attempted: \n {steps}".format(steps=request.node.description))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030028 except BaseException as e:
Hanna Arhipova1eef8312019-05-06 20:14:18 +030029 logging.info("Error in show_test_steps fixture: {}".format(e))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030030 pass