Skip to content

Commit 9b6fa90

Browse files
Fix imports for test_testing directory
1 parent cd0cc25 commit 9b6fa90

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/python_testing/test_testing/MockTestRunner.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,11 @@
1919
import os
2020
from pathlib import Path
2121
from unittest.mock import MagicMock
22+
import sys
2223

2324
from chip.clusters import Attribute
2425
from matter_testing_support.matter_testing import MatterStackState, MatterTestConfig, run_tests_no_exit
2526

26-
# import sys
27-
# try:
28-
# from matter_testing_support.matter_testing import MatterStackState, MatterTestConfig, run_tests_no_exit
29-
# except ImportError:
30-
# sys.path.append(os.path.abspath(
31-
# os.path.join(os.path.dirname(__file__), '..')))
32-
# from matter_testing_support.matter_testing import MatterStackState, MatterTestConfig, run_tests_no_exit
33-
3427

3528
class AsyncMock(MagicMock):
3629
async def __call__(self, *args, **kwargs):
@@ -56,7 +49,15 @@ def __init__(self, filename: str, classname: str, test: str, endpoint: int = 0,
5649
def set_test(self, filename: str, classname: str, test: str):
5750
self.test = test
5851
self.set_test_config()
59-
module = importlib.import_module(Path(os.path.basename(filename)).stem)
52+
53+
module_name = Path(os.path.basename(filename)).stem
54+
55+
try:
56+
module = importlib.import_module(module_name)
57+
except ModuleNotFoundError:
58+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
59+
module = importlib.import_module(module_name)
60+
6061
self.test_class = getattr(module, classname)
6162

6263
def set_test_config(self, test_config: MatterTestConfig = MatterTestConfig()):
@@ -73,7 +74,7 @@ def set_test_config(self, test_config: MatterTestConfig = MatterTestConfig()):
7374
def Shutdown(self):
7475
self.stack.Shutdown()
7576

76-
def run_test_with_mock_read(self, read_cache: Attribute.AsyncReadTransaction.ReadResponse, hooks=None):
77+
def run_test_with_mock_read(self, read_cache: Attribute.AsyncReadTransaction.ReadResponse, hooks=None):
7778
self.default_controller.Read = AsyncMock(return_value=read_cache)
7879
# This doesn't need to do anything since we are overriding the read anyway
7980
self.default_controller.FindOrEstablishPASESession = AsyncMock(return_value=None)

src/python_testing/test_testing/test_TC_ICDM_2_1.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
# limitations under the License.
1717
#
1818

19+
from MockTestRunner import MockTestRunner
1920
import string
2021
import sys
2122
from dataclasses import dataclass
2223

2324
import chip.clusters as Clusters
2425
from chip.clusters import Attribute
25-
from MockTestRunner import MockTestRunner
26+
27+
# Add the parent directory to sys.path to allow importing
28+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
2629

2730
c = Clusters.IcdManagement
2831
attr = c.Attributes

0 commit comments

Comments
 (0)