From b8d6434d5d2882ed9fbd6735623749783935bbb0 Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Thu, 12 Jan 2023 18:01:02 +0100 Subject: [PATCH] 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. (cherry picked from commit 527ac6ad269105a989c726871d8ec503ef0d69f9) --- bin/tests/system/conftest.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/tests/system/conftest.py b/bin/tests/system/conftest.py index 84a160f8bd..4b9dccdc8e 100644 --- a/bin/tests/system/conftest.py +++ b/bin/tests/system/conftest.py @@ -64,9 +64,22 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0": # Silence warnings caused by passing a pytest fixture to another fixture. # pylint: disable=redefined-outer-name + # ----------------- Older pytest / xdist compatibility ------------------- + # As of 2023-01-11, the minimal supported pytest / xdist versions are + # determined by what is available in EL8/EPEL8: + # - pytest 3.4.2 + # - pytest-xdist 1.24.1 + _pytest_ver = pytest.__version__.split(".") + _pytest_major_ver = int(_pytest_ver[0]) + if _pytest_major_ver < 7: + # pytest.Stash/pytest.StashKey mechanism has been added in 7.0.0 + # for older versions, use regular dictionary with string keys instead + FIXTURE_OK = "fixture_ok" # type: Any + else: + FIXTURE_OK = pytest.StashKey[bool]() # pylint: disable=no-member + # ----------------------- Globals definition ----------------------------- - FIXTURE_OK = pytest.StashKey[bool]() # pylint: disable=no-member LOG_FORMAT = "%(asctime)s %(levelname)7s:%(name)s %(message)s" XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER", "") FILE_DIR = os.path.abspath(Path(__file__).parent) @@ -458,6 +471,8 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0": port = int(env["PORT"]) logger.info("using port range: <%d, %d>", port, port + PORTS_PER_TEST - 1) + if not hasattr(request.node, "stash"): # compatibility with pytest<7.0.0 + request.node.stash = {} # use regular dict instead of pytest.Stash request.node.stash[FIXTURE_OK] = True # Perform checks which may skip this test.