From e778ea7498abe6543ba4712ef4b31a952f2de711 Mon Sep 17 00:00:00 2001 From: Hake Huang Date: Fri, 15 Nov 2024 21:33:24 +0800 Subject: [PATCH] twister: test: update test case 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 Signed-off-by: Hake Huang --- scripts/tests/twister/test_errors.py | 4 ++-- scripts/tests/twister/test_handlers.py | 2 +- scripts/tests/twister/test_testsuite.py | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/tests/twister/test_errors.py b/scripts/tests/twister/test_errors.py index 8968b6a1fa1e40f..0396ee109f8f437 100644 --- a/scripts/tests/twister/test_errors.py +++ b/scripts/tests/twister/test_errors.py @@ -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" diff --git a/scripts/tests/twister/test_handlers.py b/scripts/tests/twister/test_handlers.py index 122f68839638749..c6da53875233a93 100644 --- a/scripts/tests/twister/test_handlers.py +++ b/scripts/tests/twister/test_handlers.py @@ -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 diff --git a/scripts/tests/twister/test_testsuite.py b/scripts/tests/twister/test_testsuite.py index e297b6b6d9cd6c8..b077c5fb07245b9 100644 --- a/scripts/tests/twister/test_testsuite.py +++ b/scripts/tests/twister/test_testsuite.py @@ -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