diff --git a/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py b/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py index b2486f03..98e750e4 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py +++ b/test_collections/matter/sdk_tests/support/python_testing/models/test_case.py @@ -17,7 +17,6 @@ from asyncio import sleep from enum import IntEnum from inspect import iscoroutinefunction -from multiprocessing.managers import BaseManager from pathlib import Path from socket import SocketIO from typing import Any, Optional, Type, TypeVar @@ -38,10 +37,7 @@ from ...sdk_container import SDKContainer from ...utils import prompt_for_commissioning_mode from .python_test_models import PythonTest, PythonTestType -from .python_testing_hooks_proxy import ( - SDKPythonTestResultBase, - SDKPythonTestRunnerHooks, -) +from .python_testing_hooks_proxy import SDKPythonTestResultBase from .utils import ( EXECUTABLE, RUNNER_CLASS_PATH, @@ -261,9 +257,7 @@ async def execute(self) -> None: try: logger.info("Running Python Test: " + self.python_test.name) - BaseManager.register("TestRunnerHooks", SDKPythonTestRunnerHooks) - manager = BaseManager(address=("0.0.0.0", 50000), authkey=b"abc") - manager.start() + manager = self.sdk_container.manager test_runner_hooks = manager.TestRunnerHooks() # type: ignore if not self.python_test.path: diff --git a/test_collections/matter/sdk_tests/support/sdk_container.py b/test_collections/matter/sdk_tests/support/sdk_container.py index b0f6c8e2..beb2c964 100644 --- a/test_collections/matter/sdk_tests/support/sdk_container.py +++ b/test_collections/matter/sdk_tests/support/sdk_container.py @@ -15,6 +15,7 @@ # from __future__ import annotations +from multiprocessing.managers import BaseManager from pathlib import Path from typing import Optional, Union @@ -29,6 +30,7 @@ from .exec_run_in_container import ExecResultExtended, exec_run_in_container from .pics import set_pics_command +from .python_testing.models.python_testing_hooks_proxy import SDKPythonTestRunnerHooks # Trace mount LOCAL_LOGS_PATH = Path("/var/tmp") @@ -136,6 +138,7 @@ def __init__( self.__pics_file_created = False self.logger = logger + self.manager: BaseManager | None = None @property def pics_file_created(self) -> bool: @@ -150,6 +153,13 @@ def __destroy_existing_container(self) -> None: ) container_manager.destroy(existing_container) + def __create_manager(self) -> BaseManager: + BaseManager.register("TestRunnerHooks", SDKPythonTestRunnerHooks) + manager = BaseManager(address=("0.0.0.0", 50000), authkey=b"abc") + manager.start() + + return manager + def is_running(self) -> bool: if self.__container is None: return False @@ -176,6 +186,9 @@ async def start(self) -> None: self.image_tag, self.run_parameters ) + # Create the BaseManager for multiprocess data share + self.manager = self.__create_manager() + self.logger.info( f"{self.container_name} container started" f" with configuration: {self.run_parameters}" diff --git a/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py b/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py index abe7a897..e5577d84 100644 --- a/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py +++ b/test_collections/matter/sdk_tests/support/tests/test_sdk_container.py @@ -76,6 +76,10 @@ async def test_destroy_container_running() -> None: with mock.patch.object( target=sdk_container, attribute="is_running", return_value=False + ), mock.patch.object( + target=sdk_container, + attribute="_SDKContainer__create_manager", + return_value=None, ), mock.patch.object( target=container_manager, attribute="get_container", return_value=None ), mock.patch.object( @@ -112,6 +116,10 @@ async def test_destroy_container_once() -> None: with mock.patch.object( target=sdk_container, attribute="is_running", return_value=False + ), mock.patch.object( + target=sdk_container, + attribute="_SDKContainer__create_manager", + return_value=None, ), mock.patch.object( target=container_manager, attribute="get_container", return_value=None ), mock.patch.object( @@ -147,6 +155,10 @@ async def test_send_command_default_prefix() -> None: with mock.patch.object( target=sdk_container, attribute="is_running", return_value=False + ), mock.patch.object( + target=sdk_container, + attribute="_SDKContainer__create_manager", + return_value=None, ), mock.patch.object( target=container_manager, attribute="get_container", return_value=None ), mock.patch.object( @@ -188,6 +200,10 @@ async def test_send_command_custom_prefix() -> None: with mock.patch.object( target=sdk_container, attribute="is_running", return_value=False + ), mock.patch.object( + target=sdk_container, + attribute="_SDKContainer__create_manager", + return_value=None, ), mock.patch.object( target=container_manager, attribute="get_container", return_value=None ), mock.patch.object(