Skip to content

Commit

Permalink
twister: test: update test case
Browse files Browse the repository at this point in the history
update test cases for twister
1. test_errors.py add protection.
2. test_handlers.py change call to status
3. test_testsuite.py change call to status

The log traces for TwisterException objects only.
And the stack trace output follow the same rules for all exceptions,
but StatusAttributeError with its dedicated handlers.

Signed-off-by: Hake Huang <[email protected]>
  • Loading branch information
hakehuang committed Nov 28, 2024
1 parent 446a08e commit ac3cd20
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 1 addition & 3 deletions scripts/pylib/twister/twisterlib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
class TwisterException(Exception):
def __init__(self, message="TwisterException"):
super().__init__(message)
for line in traceback.format_stack():
logger.info(line.strip())
logger.warning("======call stack dump end============")
logger.error(''.join(["Twister call stack dump:\n"] + traceback.format_stack()[:-1]))

class TwisterRuntimeError(TwisterException):
pass
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/twister/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def test_configurationerror():
def test_status_value_error():
harness = Test()

expected_err = 'Test assigned status None,' \
expected_err = 'Test assigned status OK,' \
' which could not be cast to a TwisterStatus.'

with pytest.raises(StatusAttributeError, match=expected_err):
harness.status = None
harness.status = "OK"
2 changes: 1 addition & 1 deletion scripts/tests/twister/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_handler_final_handle_actions(mocked_instance):
handler.suite_name_check = True

harness = twisterlib.harness.Test()
harness.status = 'NONE'
harness.status = TwisterStatus.NONE
harness.detected_suite_names = mock.Mock()
harness.matched_run_id = False
harness.run_id_exists = True
Expand Down
5 changes: 4 additions & 1 deletion scripts/tests/twister/test_testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ def mock_sf(filename, *args, **kwargs):

def mock_stat(filename, *args, **kwargs):
result = mock.Mock()
type(result).st_size = sizes[filename]
# as we may call os.stat in code
# some protection need add here
if filename in sizes:
type(result).st_size = sizes[filename]

return result

Expand Down

0 comments on commit ac3cd20

Please sign in to comment.