mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-11 08:40:00 -04:00
Remove pytest<7 compatibility hacks
Minimum pytest version has been bumped to 7.0.0, thus these are no
longer needed.
(cherry picked from commit e276c3d5bd)
This commit is contained in:
parent
b1ebbcb7e0
commit
08ee4c75a5
1 changed files with 8 additions and 42 deletions
|
|
@ -18,7 +18,7 @@ import shutil
|
|||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -31,20 +31,6 @@ import isctest
|
|||
# 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 -----------------------------
|
||||
|
||||
XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER", "")
|
||||
|
|
@ -328,19 +314,10 @@ def system_test_name(request):
|
|||
return path.parent.name
|
||||
|
||||
|
||||
def _get_marker(node, marker):
|
||||
try:
|
||||
# pytest >= 4.x
|
||||
return node.get_closest_marker(marker)
|
||||
except AttributeError:
|
||||
# pytest < 4.x
|
||||
return node.get_marker(marker)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def wait_for_zones_loaded(request, servers):
|
||||
"""Wait for all zones to be loaded by specified named instances."""
|
||||
instances = _get_marker(request.node, "requires_zones_loaded")
|
||||
instances = request.node.get_closest_marker("requires_zones_loaded")
|
||||
if not instances:
|
||||
return
|
||||
|
||||
|
|
@ -480,7 +457,7 @@ def system_test_dir(request, env, system_test_name, expected_artifacts):
|
|||
shutil.copytree(system_test_root / system_test_name, testdir)
|
||||
|
||||
# Create a convenience symlink with a stable and predictable name
|
||||
module_name = SYMLINK_REPLACEMENT_RE.sub(r"\1", str(_get_node_path(request.node)))
|
||||
module_name = SYMLINK_REPLACEMENT_RE.sub(r"\1", str(request.node.path))
|
||||
symlink_dst = system_test_root / module_name
|
||||
unlink(symlink_dst)
|
||||
symlink_dst.symlink_to(os.path.relpath(testdir, start=system_test_root))
|
||||
|
|
@ -514,7 +491,7 @@ def system_test_dir(request, env, system_test_name, expected_artifacts):
|
|||
"test failure detected, keeping temporary directory %s", testdir
|
||||
)
|
||||
keep = True
|
||||
elif not request.node.stash[FIXTURE_OK]:
|
||||
elif not request.node.stash["fixture_ok"]:
|
||||
isctest.log.debug(
|
||||
"test setup/teardown issue detected, keeping temporary directory %s",
|
||||
testdir,
|
||||
|
|
@ -581,15 +558,6 @@ def _run_script(
|
|||
isctest.log.debug(" exited with %d", returncode)
|
||||
|
||||
|
||||
def _get_node_path(node) -> Path:
|
||||
if isinstance(node.parent, pytest.Session):
|
||||
if _pytest_major_ver >= 8:
|
||||
return Path()
|
||||
return Path(node.name)
|
||||
assert node.parent is not None
|
||||
return _get_node_path(node.parent) / node.name
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def shell(env, system_test_dir):
|
||||
"""Function to call a shell script with arguments."""
|
||||
|
|
@ -703,13 +671,11 @@ def system_test(
|
|||
pytest.fail(f"get_core_dumps.sh exited with {exc.returncode}")
|
||||
|
||||
os.environ.update(env) # Ensure pytests have the same env vars as shell tests.
|
||||
isctest.log.info(f"test started: {_get_node_path(request.node)}")
|
||||
isctest.log.info(f"test started: {request.node.path}")
|
||||
port = int(env["PORT"])
|
||||
isctest.log.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
|
||||
request.node.stash["fixture_ok"] = True
|
||||
|
||||
# Perform checks which may skip this test.
|
||||
check_net_interfaces()
|
||||
|
|
@ -718,7 +684,7 @@ def system_test(
|
|||
# Store the fact that this fixture hasn't successfully finished yet.
|
||||
# This is checked before temporary directory teardown to decide whether
|
||||
# it's okay to remove the directory.
|
||||
request.node.stash[FIXTURE_OK] = False
|
||||
request.node.stash["fixture_ok"] = False
|
||||
|
||||
setup_test()
|
||||
try:
|
||||
|
|
@ -729,7 +695,7 @@ def system_test(
|
|||
isctest.log.debug("test(s) finished")
|
||||
stop_servers()
|
||||
get_core_dumps()
|
||||
request.node.stash[FIXTURE_OK] = True
|
||||
request.node.stash["fixture_ok"] = True
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
|
|
|||
Loading…
Reference in a new issue