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

work around ResultLog support for pytest>=6.1 #129

Merged
merged 4 commits into from
Sep 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog
9.2 (unreleased)
----------------

- Nothing changed yet.
Other changes
+++++++++++++

- Deprecate ``--result-log``, as it was removed in pytest 6.1.0


9.1 (2020-08-26)
Expand Down
72 changes: 41 additions & 31 deletions pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import pkg_resources
import pytest
from _pytest.resultlog import ResultLog
from _pytest.runner import runtestprotocol

PYTEST_GTE_54 = pkg_resources.parse_version(
pytest.__version__
) >= pkg_resources.parse_version("5.4")

PYTEST_GTE_61 = pkg_resources.parse_version(
pytest.__version__
) >= pkg_resources.parse_version("6.1")


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


def _get_resultlog(config):
if PYTEST_GTE_54:
if PYTEST_GTE_61:
return None
elif PYTEST_GTE_54:
# hack
from _pytest.resultlog import resultlog_key

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


def _set_resultlog(config, resultlog):
if PYTEST_GTE_54:
if PYTEST_GTE_61:
pass
elif PYTEST_GTE_54:
# hack
from _pytest.resultlog import resultlog_key

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


class RerunResultLog(ResultLog):
def __init__(self, config, logfile):
ResultLog.__init__(self, config, logfile)

def pytest_runtest_logreport(self, report):
"""
Adds support for rerun report fix for issue:
https://github.com/pytest-dev/pytest-rerunfailures/issues/28
"""
if report.when != "call" and report.passed:
return
res = self.config.hook.pytest_report_teststatus(report=report)
code = res[1]
if code == "x":
longrepr = str(report.longrepr)
elif code == "X":
longrepr = ""
elif report.passed:
longrepr = ""
elif report.failed:
longrepr = str(report.longrepr)
elif report.skipped:
longrepr = str(report.longrepr[2])
elif report.outcome == "rerun":
longrepr = str(report.longrepr)
else:
longrepr = str(report.longrepr)
if not PYTEST_GTE_61:
from _pytest.resultlog import ResultLog

class RerunResultLog(ResultLog):
def __init__(self, config, logfile):
ResultLog.__init__(self, config, logfile)

def pytest_runtest_logreport(self, report):
"""
Adds support for rerun report fix for issue:
https://github.com/pytest-dev/pytest-rerunfailures/issues/28
"""
if report.when != "call" and report.passed:
return
res = self.config.hook.pytest_report_teststatus(report=report)
code = res[1]
if code == "x":
longrepr = str(report.longrepr)
elif code == "X":
longrepr = ""
elif report.passed:
longrepr = ""
elif report.failed:
longrepr = str(report.longrepr)
elif report.skipped:
longrepr = str(report.longrepr[2])
elif report.outcome == "rerun":
longrepr = str(report.longrepr)
else:
longrepr = str(report.longrepr)

self.log_outcome(report, code, longrepr)
self.log_outcome(report, code, longrepr)
6 changes: 6 additions & 0 deletions test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import time
from unittest import mock

import pkg_resources
import pytest


pytest_plugins = "pytester"

PYTEST_GTE_61 = pkg_resources.parse_version(
pytest.__version__
) >= pkg_resources.parse_version("6.1")


def temporary_failure(count=1):
return """
Expand Down Expand Up @@ -278,6 +283,7 @@ def test_pass():
assert_outcomes(result, passed=0, error=1, rerun=1)


@pytest.mark.skipif(PYTEST_GTE_61, reason="--result-log removed in pytest>=6.1")
def test_rerun_with_resultslog(testdir):
testdir.makepyfile(
"""
Expand Down