From ca4b3265cd7cf9dc7dfbbe9f7cbb8ae5b20b0848 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Wed, 11 Nov 2026 21:27:37 +0100 Subject: [PATCH] test: start embedded Radicale on a free port Under plain pytest -n 8 several workers each started Radicale on 5232, and one worker's stop() took down the server another was using. The xdist_group workaround only helped with --dist loadgroup. caldav 3.7, already the minimum, honours the port and closes what stop() used to leak, so the workarounds go. Prompt: [pick from the task list: "calendaring: embedded Radicale fails to start under pytest -n 8"] Assisted-By: Claude Opus 5.5 Reviewed-by: Tobias Brox --- CONTRIBUTING.md | 3 +-- tests/conftest.py | 13 +------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18ed2df..aa2e01e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,8 +33,7 @@ make test `make dev` also installs caldav and the embedded Xandikos and Radicale servers, which the CalDAV backend's conformance tests run against (they are -skipped when missing). Radicale listens on its default port, 5232, whatever -caldav's test helper is told, so that port must be free. +skipped when missing). ### Testing against more CalDAV servers diff --git a/tests/conftest.py b/tests/conftest.py index b7a32df..6c9e50f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,13 +37,7 @@ def serve(module: str, factory: str, config: dict[str, Any]) -> Iterator[Any]: server = getattr(testing, factory)(config) server.start() yield server - # stop() leaves these open (RadicaleServer one end of its socketpair, - # XandikosServer its thread's event loop): https://github.com/python-caldav/caldav/issues/797 - leftovers = [getattr(server, name, None) for name in ("shutdown_socket_out", "xapp_loop")] server.stop() - for leftover in leftovers: - if leftover is not None: - leftover.close() @pytest.fixture(scope="session") @@ -53,9 +47,7 @@ def xandikos_server() -> Iterator[Any]: @pytest.fixture(scope="session") def radicale_server() -> Iterator[Any]: - # RadicaleServer does not pass its port on to Radicale, which then - # listens on its default, 5232: https://github.com/python-caldav/caldav/issues/797 - yield from serve("radicale", "RadicaleServer", {}) + yield from serve("radicale", "RadicaleServer", {"port": free_port()}) # --- caldav's test servers ---------------------------------------------- @@ -146,9 +138,6 @@ def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item for name in (params.params.get(key) for key in ("caldav_server", "where")) if params else (): if name in servers: item.add_marker(pytest.mark.xdist_group(name)) - # Radicale always listens on 5232, and stop() shuts down whichever one answers there - if "radicale_server" in getattr(item, "fixturenames", ()): - item.add_marker(pytest.mark.xdist_group("Radicale")) def wait_out_search_cache(backend: Any, monkeypatch: pytest.MonkeyPatch) -> None: