Skip to content

Commit 59c1bfa

Browse files
authored
Merge pull request #6913 from nicoddemus/backport-6910
[Backport #6910] Handle unknown stats in pytest_report_teststatus hook
2 parents c9fd1bd + 3267f64 commit 59c1bfa

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

changelog/6910.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash when plugins return an unknown stats while using the ``--reportlog`` option.

src/_pytest/resultlog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def pytest_runtest_logreport(self, report):
7777
longrepr = ""
7878
elif report.passed:
7979
longrepr = ""
80-
elif report.failed:
81-
longrepr = str(report.longrepr)
8280
elif report.skipped:
8381
longrepr = str(report.longrepr[2])
82+
else:
83+
longrepr = str(report.longrepr)
8484
self.log_outcome(report, code, longrepr)
8585

8686
def pytest_collectreport(self, report):

testing/test_resultlog.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,42 @@ def test_no_resultlog_on_slaves(testdir):
193193
assert resultlog_key not in config._store
194194

195195

196+
def test_unknown_teststatus(testdir):
197+
"""Ensure resultlog correctly handles unknown status from pytest_report_teststatus
198+
199+
Inspired on pytest-rerunfailures.
200+
"""
201+
testdir.makepyfile(
202+
"""
203+
def test():
204+
assert 0
205+
"""
206+
)
207+
testdir.makeconftest(
208+
"""
209+
import pytest
210+
211+
def pytest_report_teststatus(report):
212+
if report.outcome == 'rerun':
213+
return "rerun", "r", "RERUN"
214+
215+
@pytest.hookimpl(hookwrapper=True)
216+
def pytest_runtest_makereport():
217+
res = yield
218+
report = res.get_result()
219+
if report.when == "call":
220+
report.outcome = 'rerun'
221+
"""
222+
)
223+
result = testdir.runpytest("--resultlog=result.log")
224+
result.stdout.fnmatch_lines(
225+
["test_unknown_teststatus.py r *[[]100%[]]", "* 1 rerun *"]
226+
)
227+
228+
lines = testdir.tmpdir.join("result.log").readlines(cr=0)
229+
assert lines[0] == "r test_unknown_teststatus.py::test"
230+
231+
196232
def test_failure_issue380(testdir):
197233
testdir.makeconftest(
198234
"""

0 commit comments

Comments
 (0)