Skip to content

Commit 0270f30

Browse files
committed
Check the availability of feature instead of version.
1 parent e4dbfc6 commit 0270f30

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Backwards incompatible changes
99

1010
- Drop support for Python 3.5.
1111

12+
Other changes
13+
+++++++++++++
14+
15+
- Check for the resultlog by feature and not by version as pytest master does
16+
not provide a consistent version.
17+
1218

1319
9.1.1 (2020-09-29)
1420
------------------

pytest_rerunfailures.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66
import pytest
77
from _pytest.runner import runtestprotocol
88

9+
HAS_RESULTLOG = False
10+
11+
try:
12+
from _pytest.resultlog import ResultLog
13+
14+
HAS_RESULTLOG = True
15+
except ImportError:
16+
# We have a pytest >= 6.1
17+
pass
18+
19+
920
PYTEST_GTE_54 = pkg_resources.parse_version(
1021
pytest.__version__
1122
) >= pkg_resources.parse_version("5.4")
1223

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

1825
def works_with_current_xdist():
1926
"""Returns compatibility with installed pytest-xdist version.
@@ -75,7 +82,7 @@ def pytest_configure(config):
7582

7683

7784
def _get_resultlog(config):
78-
if PYTEST_GTE_61:
85+
if not HAS_RESULTLOG:
7986
return None
8087
elif PYTEST_GTE_54:
8188
# hack
@@ -87,7 +94,7 @@ def _get_resultlog(config):
8794

8895

8996
def _set_resultlog(config, resultlog):
90-
if PYTEST_GTE_61:
97+
if not HAS_RESULTLOG:
9198
pass
9299
elif PYTEST_GTE_54:
93100
# hack
@@ -306,8 +313,7 @@ def show_rerun(terminalreporter, lines):
306313
lines.append(f"RERUN {pos}")
307314

308315

309-
if not PYTEST_GTE_61:
310-
from _pytest.resultlog import ResultLog
316+
if HAS_RESULTLOG:
311317

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

0 commit comments

Comments
 (0)