twister: remove not needed try..except
Removed redundant try..except around the code
and fixed a test for that code which was false positive.
Signed-off-by: Łukasz Fundakowski <lukasz.fundakowski@nordicsemi.no>
diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py
index 47942ba..e1936f5 100644
--- a/scripts/pylib/twister/twisterlib/environment.py
+++ b/scripts/pylib/twister/twisterlib/environment.py
@@ -23,7 +23,6 @@
import zephyr_module
from twisterlib.constants import SUPPORTED_SIMS
from twisterlib.coverage import supported_coverage_formats
-from twisterlib.error import TwisterRuntimeError
from twisterlib.log_helper import log_command
logger = logging.getLogger('twister')
@@ -1192,11 +1191,8 @@
toolchain_script = Path(ZEPHYR_BASE) / Path('cmake/verify-toolchain.cmake')
result = self.run_cmake_script([toolchain_script, "FORMAT=json"])
- try:
- if result['returncode']:
- raise TwisterRuntimeError(f"E: {result['returnmsg']}")
- except Exception as e:
- print(str(e))
+ if result['returncode'] != 0:
+ print(f"E: {result['returnmsg']}")
sys.exit(2)
self.toolchain = json.loads(result['stdout'])['ZEPHYR_TOOLCHAIN_VARIANT']
logger.info(f"Using '{self.toolchain}' toolchain.")
diff --git a/scripts/tests/twister/test_environment.py b/scripts/tests/twister/test_environment.py
index 33f0c3a..ad2b565 100644
--- a/scripts/tests/twister/test_environment.py
+++ b/scripts/tests/twister/test_environment.py
@@ -7,16 +7,15 @@
Tests for environment.py classes' methods
"""
-from unittest import mock
import os
-import pytest
import shutil
-
from contextlib import nullcontext
+from unittest import mock
+
+import pytest
import twisterlib.environment
-
TESTDATA_1 = [
(
None,
@@ -538,7 +537,7 @@
'Using \'dummy toolchain\' toolchain.'
),
(
- {'returncode': 1},
+ {'returncode': 1, "returnmsg": "something went wrong"},
2,
None
),
@@ -572,7 +571,7 @@
twisterlib.environment.TwisterEnv,
'run_cmake_script',
mock.Mock(return_value=script_result)), \
- pytest.raises(SystemExit) \
+ pytest.raises(SystemExit, match='2') \
if exit_value is not None else nullcontext() as exit_info:
twister_env.get_toolchain()