Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 1 | from fixtures.base import * |
Hanna Arhipova | 8c05e27 | 2019-04-24 11:47:31 +0300 | [diff] [blame^] | 2 | |
| 3 | |
| 4 | @pytest.hookimpl(tryfirst=True, hookwrapper=True) |
| 5 | def pytest_runtest_makereport(item, call): |
| 6 | outcome = yield |
| 7 | |
| 8 | rep = outcome.get_result() |
| 9 | setattr(item, "rep_" + rep.when, rep) |
| 10 | rep.description = "{}".format(str(item.function.__doc__)) |
| 11 | setattr(item, 'description', item.function.__doc__) |
| 12 | |
| 13 | |
| 14 | @pytest.fixture(autouse=True) |
| 15 | def show_test_steps(request): |
| 16 | yield |
| 17 | # request.node is an "item" because we use the default |
| 18 | # "function" scope |
| 19 | if request.node.description is None or request.node.description == "None": |
| 20 | return |
| 21 | try: |
| 22 | if request.node.rep_setup.failed: |
| 23 | print("setup failed. The following steps were attempted: \n {steps}".format(steps=request.node.description)) |
| 24 | elif request.node.rep_setup.passed: |
| 25 | if request.node.rep_call.failed: |
| 26 | print("test execution failed! The following steps were attempted: \n {steps}".format(steps=request.node.description)) |
| 27 | except BaseException as e: |
| 28 | print("Error in show_test_steps fixture: {}".format(e)) |
| 29 | pass |