Skip to content

Commit 04200e4

Browse files
committed
Make system tests compatible with pytest 8.0.0+
The pytest collection mechanism has been overhauled in pytest 8.0.0, resulting in a different node tree when collecting the tests. Ensure the paths / names we're using that are derived from the node tree are consistent across different pytest versions. Particularly, this has affected the convenience symlink name (which is supposed to be in the form of e.g. dns64_sh_dns64 for the dns64 module and tests_sh_dns64.py module) and the test name that's logged at the start of the test, which is supposed to include the system test directory relative to the root system test directory as well as the module name (e.g. dns64/tests_sh_dns64.py). Related pytest-dev/pytest#7777 (cherry picked from commit 7118cbe)
1 parent c1b82c1 commit 04200e4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bin/tests/system/conftest.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def unlink(path):
355355
isctest.vars.dirs.set_system_test_name(testdir.name)
356356

357357
# Create a convenience symlink with a stable and predictable name
358-
module_name = SYMLINK_REPLACEMENT_RE.sub(r"\1", request.node.name)
358+
module_name = SYMLINK_REPLACEMENT_RE.sub(r"\1", str(_get_node_path(request.node)))
359359
symlink_dst = system_test_root / module_name
360360
unlink(symlink_dst)
361361
symlink_dst.symlink_to(os.path.relpath(testdir, start=system_test_root))
@@ -446,6 +446,15 @@ def _run_script(
446446
isctest.log.debug(" exited with %d", returncode)
447447

448448

449+
def _get_node_path(node) -> Path:
450+
if isinstance(node.parent, pytest.Session):
451+
if _pytest_major_ver >= 8:
452+
return Path()
453+
return Path(node.name)
454+
assert node.parent is not None
455+
return _get_node_path(node.parent) / node.name
456+
457+
449458
@pytest.fixture(scope="module")
450459
def shell(system_test_dir):
451460
"""Function to call a shell script with arguments."""
@@ -543,7 +552,7 @@ def get_core_dumps():
543552
isctest.log.error("Found core dumps or sanitizer reports")
544553
pytest.fail(f"get_core_dumps.sh exited with {exc.returncode}")
545554

546-
isctest.log.info(f"test started: {request.node.name}")
555+
isctest.log.info(f"test started: {_get_node_path(request.node)}")
547556
port = int(os.environ["PORT"])
548557
isctest.log.info(
549558
"using port range: <%d, %d>", port, port + isctest.vars.ports.PORTS_PER_TEST - 1

0 commit comments

Comments
 (0)