Skip to content

Commit

Permalink
logs: log actual pytest test failure
Browse files Browse the repository at this point in the history
The failure will be logged in test.log so all information to debug
the failure is in one place.
  • Loading branch information
pbrezina committed Mar 14, 2024
1 parent 45247e2 commit 6d6182b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pytest_mh/_private/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pytest_mh/_private/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions pytest_mh/_private/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6d6182b

Please sign in to comment.