Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit c902fa5

Browse files
committed
Ensure compatiblity with older pytest
Special care needs to be taken to support older pytest / xdist versions. The target versions are what is available in EL8, since that seems to have the oldest versions that can be reasonably supported.
1 parent 0c2bdbc commit c902fa5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

bin/tests/system/conftest.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@ def control_port():
6464
# Silence warnings caused by passing a pytest fixture to another fixture.
6565
# pylint: disable=redefined-outer-name
6666

67+
# ----------------- Older pytest / xdist compatibility -------------------
68+
# As of 2023-01-11, the minimal supported pytest / xdist versions are
69+
# determined by what is available in EL8/EPEL8:
70+
# - pytest 3.4.2
71+
# - pytest-xdist 1.24.1
72+
_pytest_ver = pytest.__version__.split(".")
73+
_pytest_major_ver = int(_pytest_ver[0])
74+
if _pytest_major_ver < 7:
75+
# pytest.Stash/pytest.StashKey mechanism has been added in 7.0.0
76+
# for older versions, use regular dictionary with string keys instead
77+
FIXTURE_OK = "fixture_ok" # type: Any
78+
else:
79+
FIXTURE_OK = pytest.StashKey[bool]() # pylint: disable=no-member
80+
6781
# ----------------------- Globals definition -----------------------------
6882

69-
FIXTURE_OK = pytest.StashKey[bool]() # pylint: disable=no-member
7083
LOG_FORMAT = "%(asctime)s %(levelname)7s:%(name)s %(message)s"
7184
XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER", "")
7285
FILE_DIR = os.path.abspath(Path(__file__).parent)
@@ -458,6 +471,8 @@ def get_core_dumps():
458471
port = int(env["PORT"])
459472
logger.info("using port range: <%d, %d>", port, port + PORTS_PER_TEST - 1)
460473

474+
if not hasattr(request.node, "stash"): # compatibility with pytest<7.0.0
475+
request.node.stash = {} # use regular dict instead of pytest.Stash
461476
request.node.stash[FIXTURE_OK] = True
462477

463478
# Perform checks which may skip this test.

0 commit comments

Comments
 (0)