From dc1946810b94b2c4df69d80233e318ee957b2bb3 Mon Sep 17 00:00:00 2001 From: urob <978080+urob@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:30:46 -0400 Subject: [PATCH] Support west test when invoked as module --- app/scripts/west_commands/test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/scripts/west_commands/test.py b/app/scripts/west_commands/test.py index 531334913b4..737622dea03 100644 --- a/app/scripts/west_commands/test.py +++ b/app/scripts/west_commands/test.py @@ -2,11 +2,11 @@ # SPDX-License-Identifier: MIT """Test runner for ZMK.""" -import os import subprocess +from pathlib import Path -from west.commands import WestCommand from west import log # use this for user output +from west.commands import WestCommand class Test(WestCommand): @@ -17,6 +17,8 @@ def __init__(self): description="Run the ZMK testsuite.", ) + self.appdir = Path(__file__).resolve().parents[2] + def do_add_parser(self, parser_adder): parser = parser_adder.add_parser( self.name, @@ -34,8 +36,7 @@ def do_add_parser(self, parser_adder): def do_run(self, args, unknown_args): # the run-test script assumes the app directory is the current dir. - os.chdir(f"{self.topdir}/app") completed_process = subprocess.run( - [f"{self.topdir}/app/run-test.sh", args.test_path] + ["./run-test.sh", args.test_path], cwd=self.appdir ) exit(completed_process.returncode)