Merge pull request #6910 from nicoddemus/resultlog-logreport

Handle unknown stats in pytest_report_teststatus hook
This commit is contained in:
Bruno Oliveira 2020-03-13 09:30:04 -03:00 committed by GitHub
commit 2eedf9c2aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1 @@
Fix crash when plugins return an unknown stats while using the ``--reportlog`` option.

View File

@ -77,10 +77,10 @@ class ResultLog:
longrepr = "" longrepr = ""
elif report.passed: elif report.passed:
longrepr = "" longrepr = ""
elif report.failed:
longrepr = str(report.longrepr)
elif report.skipped: elif report.skipped:
longrepr = str(report.longrepr[2]) longrepr = str(report.longrepr[2])
else:
longrepr = str(report.longrepr)
self.log_outcome(report, code, longrepr) self.log_outcome(report, code, longrepr)
def pytest_collectreport(self, report): def pytest_collectreport(self, report):

View File

@ -193,6 +193,42 @@ def test_no_resultlog_on_slaves(testdir):
assert resultlog_key not in config._store assert resultlog_key not in config._store
def test_unknown_teststatus(testdir):
"""Ensure resultlog correctly handles unknown status from pytest_report_teststatus
Inspired on pytest-rerunfailures.
"""
testdir.makepyfile(
"""
def test():
assert 0
"""
)
testdir.makeconftest(
"""
import pytest
def pytest_report_teststatus(report):
if report.outcome == 'rerun':
return "rerun", "r", "RERUN"
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport():
res = yield
report = res.get_result()
if report.when == "call":
report.outcome = 'rerun'
"""
)
result = testdir.runpytest("--resultlog=result.log")
result.stdout.fnmatch_lines(
["test_unknown_teststatus.py r *[[]100%[]]", "* 1 rerun *"]
)
lines = testdir.tmpdir.join("result.log").readlines(cr=0)
assert lines[0] == "r test_unknown_teststatus.py::test"
def test_failure_issue380(testdir): def test_failure_issue380(testdir):
testdir.makeconftest( testdir.makeconftest(
""" """