diff --git a/lib/iris/tests/cluster/controller/conftest.py b/lib/iris/tests/cluster/controller/conftest.py index a06c6190ea..101259d683 100644 --- a/lib/iris/tests/cluster/controller/conftest.py +++ b/lib/iris/tests/cluster/controller/conftest.py @@ -12,6 +12,7 @@ import pytest +from iris.managed_thread import thread_container_scope from iris.cluster.bundle import BundleStore from iris.cluster.constraints import ( Constraint, @@ -112,6 +113,17 @@ def close(self) -> None: pass +@pytest.fixture(autouse=True) +def _isolated_thread_container(): + """Install a per-test ThreadContainer so Controller-spawned threads are + stopped at test end. Without this, tests that construct a Controller but + never call ``.stop()`` leak the uvicorn log-server thread and hit the 5s + leak-detection wait in the top-level ``_thread_cleanup`` fixture. + """ + with thread_container_scope(name="controller-test"): + yield + + @pytest.fixture def state(): """Create a fresh ControllerTransitions with temp DB and log store."""