Skip to content

Commit 04b5e9c

Browse files
authored
Merge pull request #129 from ntessore/remove-resultlog
work around ResultLog support for pytest>=6.1
2 parents 87c2974 + dca99eb commit 04b5e9c

3 files changed

Lines changed: 51 additions & 32 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Changelog
44
9.2 (unreleased)
55
----------------
66

7-
- Nothing changed yet.
7+
Other changes
8+
+++++++++++++
9+
10+
- Deprecate ``--result-log``, as it was removed in pytest 6.1.0
811

912

1013
9.1 (2020-08-26)

pytest_rerunfailures.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
import pkg_resources
66
import pytest
7-
from _pytest.resultlog import ResultLog
87
from _pytest.runner import runtestprotocol
98

109
PYTEST_GTE_54 = pkg_resources.parse_version(
1110
pytest.__version__
1211
) >= pkg_resources.parse_version("5.4")
1312

13+
PYTEST_GTE_61 = pkg_resources.parse_version(
14+
pytest.__version__
15+
) >= pkg_resources.parse_version("6.1")
16+
1417

1518
def works_with_current_xdist():
1619
"""Returns compatibility with installed pytest-xdist version.
@@ -72,7 +75,9 @@ def pytest_configure(config):
7275

7376

7477
def _get_resultlog(config):
75-
if PYTEST_GTE_54:
78+
if PYTEST_GTE_61:
79+
return None
80+
elif PYTEST_GTE_54:
7681
# hack
7782
from _pytest.resultlog import resultlog_key
7883

@@ -82,7 +87,9 @@ def _get_resultlog(config):
8287

8388

8489
def _set_resultlog(config, resultlog):
85-
if PYTEST_GTE_54:
90+
if PYTEST_GTE_61:
91+
pass
92+
elif PYTEST_GTE_54:
8693
# hack
8794
from _pytest.resultlog import resultlog_key
8895

@@ -299,32 +306,35 @@ def show_rerun(terminalreporter, lines):
299306
lines.append("RERUN {}".format(pos))
300307

301308

302-
class RerunResultLog(ResultLog):
303-
def __init__(self, config, logfile):
304-
ResultLog.__init__(self, config, logfile)
305-
306-
def pytest_runtest_logreport(self, report):
307-
"""
308-
Adds support for rerun report fix for issue:
309-
https://github.com/pytest-dev/pytest-rerunfailures/issues/28
310-
"""
311-
if report.when != "call" and report.passed:
312-
return
313-
res = self.config.hook.pytest_report_teststatus(report=report)
314-
code = res[1]
315-
if code == "x":
316-
longrepr = str(report.longrepr)
317-
elif code == "X":
318-
longrepr = ""
319-
elif report.passed:
320-
longrepr = ""
321-
elif report.failed:
322-
longrepr = str(report.longrepr)
323-
elif report.skipped:
324-
longrepr = str(report.longrepr[2])
325-
elif report.outcome == "rerun":
326-
longrepr = str(report.longrepr)
327-
else:
328-
longrepr = str(report.longrepr)
309+
if not PYTEST_GTE_61:
310+
from _pytest.resultlog import ResultLog
311+
312+
class RerunResultLog(ResultLog):
313+
def __init__(self, config, logfile):
314+
ResultLog.__init__(self, config, logfile)
315+
316+
def pytest_runtest_logreport(self, report):
317+
"""
318+
Adds support for rerun report fix for issue:
319+
https://github.com/pytest-dev/pytest-rerunfailures/issues/28
320+
"""
321+
if report.when != "call" and report.passed:
322+
return
323+
res = self.config.hook.pytest_report_teststatus(report=report)
324+
code = res[1]
325+
if code == "x":
326+
longrepr = str(report.longrepr)
327+
elif code == "X":
328+
longrepr = ""
329+
elif report.passed:
330+
longrepr = ""
331+
elif report.failed:
332+
longrepr = str(report.longrepr)
333+
elif report.skipped:
334+
longrepr = str(report.longrepr[2])
335+
elif report.outcome == "rerun":
336+
longrepr = str(report.longrepr)
337+
else:
338+
longrepr = str(report.longrepr)
329339

330-
self.log_outcome(report, code, longrepr)
340+
self.log_outcome(report, code, longrepr)

test_pytest_rerunfailures.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
import time
33
from unittest import mock
44

5+
import pkg_resources
56
import pytest
67

78

89
pytest_plugins = "pytester"
910

11+
PYTEST_GTE_61 = pkg_resources.parse_version(
12+
pytest.__version__
13+
) >= pkg_resources.parse_version("6.1")
14+
1015

1116
def temporary_failure(count=1):
1217
return """
@@ -278,6 +283,7 @@ def test_pass():
278283
assert_outcomes(result, passed=0, error=1, rerun=1)
279284

280285

286+
@pytest.mark.skipif(PYTEST_GTE_61, reason="--result-log removed in pytest>=6.1")
281287
def test_rerun_with_resultslog(testdir):
282288
testdir.makepyfile(
283289
"""

0 commit comments

Comments
 (0)