From 6d6182ba7ae4afd5273586ea54e2a77acede7f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= Date: Thu, 14 Mar 2024 15:36:02 +0100 Subject: [PATCH] logs: log actual pytest test failure The failure will be logged in test.log so all information to debug the failure is in one place. --- pytest_mh/_private/data.py | 5 +++++ pytest_mh/_private/fixtures.py | 3 +++ pytest_mh/_private/plugin.py | 1 + 3 files changed, 9 insertions(+) diff --git a/pytest_mh/_private/data.py b/pytest_mh/_private/data.py index 71044a2..76036ef 100644 --- a/pytest_mh/_private/data.py +++ b/pytest_mh/_private/data.py @@ -28,6 +28,11 @@ def __init__(self, multihost: MultihostConfig | None, topology_mark: TopologyMar Test run outcome, available in fixture finalizers. """ + self.result: pytest.TestReport | None = None + """ + Pytest test result. + """ + def _init(self) -> None: """ Postponed initialization. This is called once we know that current diff --git a/pytest_mh/_private/fixtures.py b/pytest_mh/_private/fixtures.py index 08d8926..d73621b 100644 --- a/pytest_mh/_private/fixtures.py +++ b/pytest_mh/_private/fixtures.py @@ -384,5 +384,8 @@ def mh(request: pytest.FixtureRequest) -> Generator[MultihostFixture, None, None yield mh mh.log_phase("TEST DONE") finally: + if data.outcome == "failed" and data.result is not None: + mh.logger.error(data.result.longreprtext) + mh.split_log_file("test.log") mh._exit() diff --git a/pytest_mh/_private/plugin.py b/pytest_mh/_private/plugin.py index 7b9597a..5e165e4 100644 --- a/pytest_mh/_private/plugin.py +++ b/pytest_mh/_private/plugin.py @@ -364,6 +364,7 @@ def pytest_runtest_makereport( return data.outcome = result.outcome + data.result = result # Hook from pytest-output plugin @pytest.hookimpl(optionalhook=True)