From ba2958f412b830d08b115e12cf1c812ec5dd35df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicki=20K=C5=99=C3=AD=C5=BEek?= Date: Tue, 17 Mar 2026 17:08:15 +0100 Subject: [PATCH] Use underscore for system test names Change the convention for system test directory names to always use an underscore rather than a hyphen. Names using underscore are valid python package names and can be used with standard `import` facilities in python, which allows easier code reuse. The temporary directories for test execution and their convenience symlinks have been switched to using hyphens rather than underscores to keep the pytest collection, filtering and .gitignore working as expected. (cherry picked from commit 9f4c1d1993fe624c5d68cbc51521dd4761513cd2) --- bin/tests/system/.gitignore | 9 ++++----- bin/tests/system/Makefile.am | 14 +++++++------- bin/tests/system/conftest.py | 10 +++++----- dangerfile.py | 6 +++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/bin/tests/system/.gitignore b/bin/tests/system/.gitignore index f946793ae7..6c34bfcd1a 100644 --- a/bin/tests/system/.gitignore +++ b/bin/tests/system/.gitignore @@ -24,10 +24,9 @@ parallel.mk /stop.sh /ifconfig.sh -# Ignore file names with underscore in their name except python or shell files. +# Ignore file names with a hyphen in their name except C files. # This is done to ignore the temporary directories and symlinks created by the # pytest runner, which contain underscore in their file names. -/*_* -!/*_*.py -!/*_*.sh -!/_common +/*-* +!/*-*.c +!/custom-test-driver diff --git a/bin/tests/system/Makefile.am b/bin/tests/system/Makefile.am index d4526d2dd8..57b019bdc5 100644 --- a/bin/tests/system/Makefile.am +++ b/bin/tests/system/Makefile.am @@ -88,13 +88,13 @@ tkey_keydelete_LDADD = \ TESTS = \ rpz \ rpzrecurse \ - serve-stale \ + serve_stale \ timeouts \ upforwd \ acl \ additional \ addzone \ - allow-query \ + allow_query \ auth \ autosign \ builtin \ @@ -117,7 +117,7 @@ TESTS = \ dlzexternal \ dns64 \ dnssec \ - dnssec-malformed-dnskey \ + dnssec_malformed_dnskey \ dnstap \ doth \ dsdigest \ @@ -128,14 +128,14 @@ TESTS = \ ednscompliance \ emptyzones \ enginepkcs11 \ - filter-aaaa \ + filter_aaaa \ fetchlimit \ formerr \ forward \ geoip2 \ glue \ idna \ - include-multiplecfg \ + include_multiplecfg \ inline \ integrity \ ixfr \ @@ -189,7 +189,7 @@ TESTS = \ tcp \ tkey \ tools \ - transport-acl \ + transport_acl \ tsig \ tsiggss \ ttl \ @@ -231,4 +231,4 @@ LOG_COMPILER = $(srcdir)/run.sh test-local: check clean-local:: - -find -L . -mindepth 1 -maxdepth 1 -type d -name "*_*" -and -not -name "_common" -exec rm -rf {} \; + -find -L . -mindepth 1 -maxdepth 1 -type d -name "*-*" -exec rm -rf {} \; diff --git a/bin/tests/system/conftest.py b/bin/tests/system/conftest.py index 8fc9dd8a11..2f84bb108b 100644 --- a/bin/tests/system/conftest.py +++ b/bin/tests/system/conftest.py @@ -53,7 +53,7 @@ PRIORITY_TESTS = [ PRIORITY_TESTS_RE = Re("|".join(PRIORITY_TESTS)) SYSTEM_TEST_DIR_GIT_PATH = "bin/tests/system" SYSTEM_TEST_NAME_RE = Re(f"{SYSTEM_TEST_DIR_GIT_PATH}" + r"/([^/]+)") -SYMLINK_REPLACEMENT_RE = Re(r"/tests(_.*)\.py") +SYMLINK_REPLACEMENT_RE = Re(r"/tests_(.*)\.py") # ---------------------- Module initialization --------------------------- @@ -132,14 +132,14 @@ def pytest_ignore_collect(collection_path): # ignore these during test collection phase. Otherwise, test artifacts # from previous runs could mess with the runner. Also ignore the # convenience symlinks to those test directories. In both of those - # cases, the system test name (directory) contains an underscore, which + # cases, the system test name (directory) contains a hyphen, which # is otherwise and invalid character for a system test name. match = SYSTEM_TEST_NAME_RE.search(str(collection_path)) if match is None: isctest.log.warning("unexpected test path: %s (ignored)", collection_path) return True system_test_name = match.groups()[0] - return "_" in system_test_name + return "-" in system_test_name def pytest_collection_modifyitems(items): @@ -449,13 +449,13 @@ def system_test_dir(request, env, system_test_name, expected_artifacts): f"{env['TOP_BUILDDIR']}/{SYSTEM_TEST_DIR_GIT_PATH}" ).resolve() testdir = Path( - tempfile.mkdtemp(prefix=f"{system_test_name}_tmp_", dir=system_test_root) + tempfile.mkdtemp(prefix=f"{system_test_name}-tmp-", dir=system_test_root) ) shutil.rmtree(testdir) 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(request.node.path)) + module_name = SYMLINK_REPLACEMENT_RE.sub(r"-\1", str(request.node.path)) symlink_dst = system_test_root / module_name symlink_dst.unlink(missing_ok=True) symlink_dst.symlink_to(os.path.relpath(testdir, start=system_test_root)) diff --git a/dangerfile.py b/dangerfile.py index b6851be7a5..c716934f09 100644 --- a/dangerfile.py +++ b/dangerfile.py @@ -494,10 +494,10 @@ for testname in testnames: or testname == "isctest" ): continue - if "_" in testname: + if "-" in testname: fail( - f"System test directory `{testname}` may not contain an underscore, " - "use hyphen instead." + f"System test directory `{testname}` may not contain a hyphen, " + "use underscore instead." ) if not glob.glob(f"{dirpath}/**/tests_*.py", recursive=True): fail(