blob: d03edfa792cedafd1a9003fc81582e1aca92f4e6 [file] [log] [blame]
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +03001from builtins import str
2import pytest
3from fixtures.base import (
4 print_node_version,
5 check_cicd,
6 check_kfg,
7 check_kdt,
8 contrail,
9 check_cinder_backends,
10 check_grafana,
11 check_kibana,
12 check_alerta,
13 check_prometheus,
14 check_openstack,
15 check_ironic,
16 check_drivetrain,
17 check_openstack,
18 ctl_nodes_pillar,
19 nodes_in_group,
20 local_salt_client,
21 add_testname_to_saltapi_logs,)
Hanna Arhipova56eab942019-05-06 20:14:18 +030022import logging
Hanna Arhipova8c05e272019-04-24 11:47:31 +030023
24
25@pytest.hookimpl(tryfirst=True, hookwrapper=True)
26def pytest_runtest_makereport(item, call):
27 outcome = yield
28
29 rep = outcome.get_result()
30 setattr(item, "rep_" + rep.when, rep)
31 rep.description = "{}".format(str(item.function.__doc__))
32 setattr(item, 'description', item.function.__doc__)
33
34
35@pytest.fixture(autouse=True)
36def show_test_steps(request):
37 yield
38 # request.node is an "item" because we use the default
39 # "function" scope
40 if request.node.description is None or request.node.description == "None":
41 return
42 try:
43 if request.node.rep_setup.failed:
Hanna Arhipova56eab942019-05-06 20:14:18 +030044 logging.warning("setup failed. The following steps were attempted: \n {steps}".format(steps=request.node.description))
Hanna Arhipova8c05e272019-04-24 11:47:31 +030045 elif request.node.rep_setup.passed:
46 if request.node.rep_call.failed:
Hanna Arhipova56eab942019-05-06 20:14:18 +030047 logging.warning("test execution failed! The following steps were attempted: \n {steps}".format(steps=request.node.description))
Hanna Arhipova8c05e272019-04-24 11:47:31 +030048 except BaseException as e:
Hanna Arhipova56eab942019-05-06 20:14:18 +030049 logging.info("Error in show_test_steps fixture: {}".format(e))
Hanna Arhipova8c05e272019-04-24 11:47:31 +030050 pass