From 97948488bd5c5534d927bd084265399c3adafa01 Mon Sep 17 00:00:00 2001 From: Christian Sandberg Date: Thu, 5 Nov 2020 20:55:12 +0100 Subject: [PATCH] Support pytest < 6.0 again Fixes #5 --- pytest_reporter/plugin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pytest_reporter/plugin.py b/pytest_reporter/plugin.py index 72ce1d5..2d01e09 100644 --- a/pytest_reporter/plugin.py +++ b/pytest_reporter/plugin.py @@ -6,6 +6,7 @@ from itertools import chain import pytest +import _pytest.hookspec def pytest_addoption(parser): @@ -165,8 +166,13 @@ def pytest_runtest_logfinish(self, nodeid): self.context["tests"].append(testrun) del self._active_tests[nodeid] - def pytest_warning_recorded(self, warning_message): - self.context["warnings"].append(warning_message) + # the pytest_warning_recorded hook was introduced in pytest 6.0 + if hasattr(_pytest.hookspec, "pytest_warning_recorded"): + def pytest_warning_recorded(self, warning_message): + self.context["warnings"].append(warning_message) + else: + def pytest_warning_captured(self, warning_message): + self.context["warnings"].append(warning_message) def pytest_sessionfinish(self, session): self.context["ended"] = time.time()