Commit a3e5f5a202 for bind
commit a3e5f5a20202f4ff1b70f09aa4f94023230bdf79
Author: Nicki Křížek <nicki@isc.org>
Date: Thu Dec 3 16:18:41 2026 +0000
Reject explicit imports of the isctest submodules in tests
Add a pylint checker that keeps the tests on "import isctest" alone,
and state the rule in the README. The modules of the isctest package
keep importing each other explicitly.
diff --git a/bin/tests/system/README.md b/bin/tests/system/README.md
index 9c1678c844..573d364309 100644
--- a/bin/tests/system/README.md
+++ b/bin/tests/system/README.md
@@ -335,6 +335,12 @@ responses), `isctest.zone` (zone and key setup), `isctest.kasp` (DNSSEC
key state checks), `isctest.asyncserver` (mock servers) and `isctest.log`
(logging and log watchers).
+A test module needs only `import isctest`: the package loads a submodule
+when it is first used, e.g. as `isctest.query.udp(...)`. Don't add
+`import isctest.<submodule>` or an import of anything below it; pylint
+rejects both. Importing names with
+`from isctest.<submodule> import ...` is fine.
+
Pytest marks control test collection and setup:
- `@pytest.mark.extra_artifacts([...])` declares the files (globs) the test is
diff --git a/bin/tests/system/isctest_import_checker.py b/bin/tests/system/isctest_import_checker.py
new file mode 100644
index 0000000000..75d6789d55
--- /dev/null
+++ b/bin/tests/system/isctest_import_checker.py
@@ -0,0 +1,54 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from pathlib import Path
+
+from pylint.checkers import BaseChecker
+
+import isctest
+
+
+class IsctestImportsChecker(BaseChecker):
+ name = "isctest-imports"
+
+ msgs = {
+ "W9007": (
+ "Redundant 'import %s'; 'import isctest' loads it on first use",
+ "isctest-redundant-submodule-import",
+ "Emitted when a test imports a submodule that the isctest package "
+ "loads on first use.",
+ ),
+ }
+
+ def visit_import(self, node):
+ if self._in_isctest_library(node):
+ return
+ for name, _asname in node.names:
+ package, submodule, *_ = name.split(".") + [""]
+ if package == "isctest" and submodule in isctest.__all__:
+ self.add_message(
+ "isctest-redundant-submodule-import", node=node, args=(name,)
+ )
+
+ @staticmethod
+ def _in_isctest_library(node):
+ """
+ The modules of the package import each other explicitly; the tests
+ the package carries follow the rule for tests.
+ """
+ parts = Path(node.root().file).parts
+ if "isctest" not in parts:
+ return False
+ return "tests" not in parts[parts.index("isctest") :]
+
+
+def register(linter):
+ linter.register_checker(IsctestImportsChecker(linter))
diff --git a/pyproject.toml b/pyproject.toml
index 3550a697e5..580b7e5384 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -61,6 +61,7 @@ load-plugins = [
"dns_import_checker",
"docstring_format_checker",
"file_header_checker",
+ "isctest_import_checker",
]
[tool.vulture]
@@ -79,6 +80,7 @@ exclude = [
"dns_import_checker.py",
"docstring_format_checker.py",
"file_header_checker.py",
+ "isctest_import_checker.py",
]
ignore_decorators = [
"@pytest.fixture",