Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport #6910] Handle unknown stats in pytest_report_teststatus hook #6913

Merged
merged 1 commit into from Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/6910.bugfix.rst
@@ -0,0 +1 @@
Fix crash when plugins return an unknown stats while using the ``--reportlog`` option.
4 changes: 2 additions & 2 deletions src/_pytest/resultlog.py
Expand Up @@ -77,10 +77,10 @@ def pytest_runtest_logreport(self, report):
longrepr = ""
elif report.passed:
longrepr = ""
elif report.failed:
longrepr = str(report.longrepr)
elif report.skipped:
longrepr = str(report.longrepr[2])
else:
longrepr = str(report.longrepr)
self.log_outcome(report, code, longrepr)

def pytest_collectreport(self, report):
Expand Down
36 changes: 36 additions & 0 deletions testing/test_resultlog.py
Expand Up @@ -193,6 +193,42 @@ def test_no_resultlog_on_slaves(testdir):
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):
testdir.makeconftest(
"""
Expand Down