Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 1 | from fixtures.base import * |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame^] | 2 | import logging |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame] | 3 | |
| 4 | |
| 5 | @pytest.hookimpl(tryfirst=True, hookwrapper=True) |
| 6 | def 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) |
| 16 | def 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 Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame^] | 24 | 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] | 25 | elif request.node.rep_setup.passed: |
| 26 | if request.node.rep_call.failed: |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame^] | 27 | 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] | 28 | except BaseException as e: |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame^] | 29 | logging.info("Error in show_test_steps fixture: {}".format(e)) |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame] | 30 | pass |