From d351a5a8a0996205211e3eae47972a541cb1f59f Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sun, 25 Oct 2026 08:41:01 +0100 Subject: [PATCH 1/2] fix: import caldav.testing.registry on its own Importing caldav.testing.registry before anything else in the package failed: registry imports base, and base imported registry back to register the external server class. The tests/test_servers package always imported base first, which hid the cycle. The external class is now registered in registry itself. Prompt: (while working with the calendaring library) Do the needful ensuring all tests are run towards all servers ... Assisted-By: Claude Opus 5.5 (1M context) Reviewed-by: Tobias Brox --- caldav/testing/base.py | 10 ---------- caldav/testing/registry.py | 8 +++++--- tests/test_testing_base.py | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/caldav/testing/base.py b/caldav/testing/base.py index 16b25633..d473c289 100644 --- a/caldav/testing/base.py +++ b/caldav/testing/base.py @@ -639,13 +639,3 @@ def is_accessible(self) -> bool: return True except (OSError, ValueError): return False - - -# Deferred registration to avoid circular imports -def _register_external_server() -> None: - from .registry import register_server_class - - register_server_class("external", ExternalTestServer) - - -_register_external_server() diff --git a/caldav/testing/registry.py b/caldav/testing/registry.py index f63fc95a..92814ba0 100644 --- a/caldav/testing/registry.py +++ b/caldav/testing/registry.py @@ -33,10 +33,12 @@ import os -from .base import TestServer +from .base import ExternalTestServer, TestServer -# Server class registry - maps type names to server classes -_SERVER_CLASSES: dict[str, type[TestServer]] = {} +# Server class registry - maps type names to server classes. The external +# class is registered here rather than in base, which must not import this +# module: base is imported first, from here. +_SERVER_CLASSES: dict[str, type[TestServer]] = {"external": ExternalTestServer} def register_server_class(type_name: str, server_class: type[TestServer]) -> None: diff --git a/tests/test_testing_base.py b/tests/test_testing_base.py index 6c822888..3bb6614e 100644 --- a/tests/test_testing_base.py +++ b/tests/test_testing_base.py @@ -348,3 +348,30 @@ def test_test_servers_submodules_are_package_attributes(monkeypatch) -> None: assert tests.test_servers.base is base monkeypatch.setattr("tests.test_servers.base.DEFAULT_HTTP_TIMEOUT", 1) assert base.DEFAULT_HTTP_TIMEOUT == 1 + + +@pytest.mark.parametrize( + "module", + [ + "caldav.testing", + "caldav.testing.base", + "caldav.testing.config_loader", + "caldav.testing.docker", + "caldav.testing.embedded", + "caldav.testing.helpers", + "caldav.testing.registry", + ], +) +def test_each_testing_module_imports_on_its_own(module: str) -> None: + """A consumer may import any submodule first; none may depend on another having been imported.""" + import os + import subprocess + import sys + + import caldav + + # This checkout's caldav, not whatever the editable install points at (a worktree's main checkout) + root = str(Path(caldav.__file__).resolve().parent.parent) + env = {**os.environ, "PYTHONPATH": os.pathsep.join([root, os.environ.get("PYTHONPATH", "")])} + code = f"import {module}; from caldav.testing.registry import get_server_class; assert get_server_class('external')" + subprocess.run([sys.executable, "-c", code], check=True, cwd=root, env=env) From d8222d5c4db786af3c58029a9c5d030d2faf4151 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sun, 25 Oct 2026 21:01:01 +0100 Subject: [PATCH 2/2] test: find the checkout without importing caldav The import test imported the caldav package beside the module's from-import of caldav.testing.base, which code scanning flags. The checkout root now comes from base.__file__. https://github.com/python-caldav/caldav/pull/828 Prompt: Fix the import for 828. [the code-scanning thread on https://github.com/python-caldav/caldav/pull/828: caldav imported with both import and from-import] Assisted-By: Claude Opus 5.5 (1M context) Reviewed-by: Tobias Brox --- tests/test_testing_base.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_testing_base.py b/tests/test_testing_base.py index 3bb6614e..cc53d0b0 100644 --- a/tests/test_testing_base.py +++ b/tests/test_testing_base.py @@ -368,10 +368,8 @@ def test_each_testing_module_imports_on_its_own(module: str) -> None: import subprocess import sys - import caldav - # This checkout's caldav, not whatever the editable install points at (a worktree's main checkout) - root = str(Path(caldav.__file__).resolve().parent.parent) + root = str(Path(base.__file__).resolve().parents[2]) env = {**os.environ, "PYTHONPATH": os.pathsep.join([root, os.environ.get("PYTHONPATH", "")])} code = f"import {module}; from caldav.testing.registry import get_server_class; assert get_server_class('external')" subprocess.run([sys.executable, "-c", code], check=True, cwd=root, env=env)