Skip to content

Commit

Permalink
Fix custom SDK python tests (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccruzagralopes authored Mar 14, 2024
1 parent 2957788 commit b5fd6c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class TestRunnerHooks:


def main() -> None:
# Load python_testing/scripts/sdk as a module. This folder is where all python
# script are located
sys.path.append("/root/python_testing/scripts/sdk")
# Load python_testing/scripts as a module. This folder is where all python scripts
# are located
sys.path.append("/root/python_testing/scripts")

test_args = sys.argv[2:]
config = parse_matter_test_args(test_args)
Expand All @@ -49,11 +49,12 @@ def main() -> None:
if sys.argv[1] == "commission":
commission(config)
else:
run_test(script_name=sys.argv[1], class_name=sys.argv[2], config=config)
run_test(script_path=sys.argv[1], class_name=sys.argv[2], config=config)


def run_test(script_name: str, class_name: str, config: MatterTestConfig) -> None:
module = importlib.import_module(script_name)
def run_test(script_path: str, class_name: str, config: MatterTestConfig) -> None:
# For a script_path like 'custom/TC_XYZ' the module is 'custom.TC_XYZ'
module = importlib.import_module(script_path.replace("/", "."))
TestClassReference = getattr(module, class_name)

BaseManager.register(TestRunnerHooks.__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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

Expand Down Expand Up @@ -244,8 +245,13 @@ async def execute(self) -> None:
f"Missing file path for python test {self.python_test.name}"
)

# get script path including folder (sdk or custom) and excluding extension
test_script_relative_path = Path(
*self.python_test.path.parts[-2:]
).with_suffix("")

command = [
f"{RUNNER_CLASS_PATH} {self.python_test.path.stem}"
f"{RUNNER_CLASS_PATH} {test_script_relative_path}"
f" {self.python_test.class_name} --tests test_{self.python_test.name}"
]

Expand Down

0 comments on commit b5fd6c6

Please sign in to comment.