Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 1 | from builtins import str |
| 2 | import pytest |
| 3 | from 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 Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 22 | import logging |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame] | 23 | |
| 24 | |
| 25 | @pytest.hookimpl(tryfirst=True, hookwrapper=True) |
| 26 | def 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) |
| 36 | def 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 Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 44 | logging.warning("setup failed. The following steps were attempted: \n {steps}".format(steps=request.node.description)) |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame] | 45 | elif request.node.rep_setup.passed: |
| 46 | if request.node.rep_call.failed: |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 47 | logging.warning("test execution failed! The following steps were attempted: \n {steps}".format(steps=request.node.description)) |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame] | 48 | except BaseException as e: |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 49 | logging.info("Error in show_test_steps fixture: {}".format(e)) |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame] | 50 | pass |