How to use mock_test_pass method in toolium

Best Python code snippet using toolium_python

test_o3de_editor_test.py

Source:test_o3de_editor_test.py Github

copy

Full Screen

1"""2Copyright (c) Contributors to the Open 3D Engine Project.3For complete copyright and license terms please see the LICENSE at the root of this distribution.4SPDX-License-Identifier: Apache-2.0 OR MIT5"""6import unittest7import pytest8import unittest.mock as mock9import ly_test_tools10import ly_test_tools.o3de.editor_test as editor_test11import ly_test_tools.launchers.exceptions12pytestmark = pytest.mark.SUITE_smoke13class TestEditorTestBase(unittest.TestCase):14 def test_EditorSharedTest_Init_CorrectAttributes(self):15 mock_editorsharedtest = editor_test.EditorSharedTest()16 assert mock_editorsharedtest.is_batchable17 assert mock_editorsharedtest.is_parallelizable18 def test_EditorParallelTest_Init_CorrectAttributes(self):19 mock_editorsharedtest = editor_test.EditorParallelTest()20 assert not mock_editorsharedtest.is_batchable21 assert mock_editorsharedtest.is_parallelizable22 def test_EditorBatchedTest_Init_CorrectAttributes(self):23 mock_editorsharedtest = editor_test.EditorBatchedTest()24 assert mock_editorsharedtest.is_batchable25 assert not mock_editorsharedtest.is_parallelizable26class TestResultBase(unittest.TestCase):27 def setUp(self):28 self.mock_result = editor_test.Result.Base()29 def test_GetOutputStr_HasOutput_ReturnsCorrectly(self):30 self.mock_result.output = 'expected output'31 assert self.mock_result.get_output_str() == 'expected output'32 def test_GetOutputStr_NoOutput_ReturnsCorrectly(self):33 self.mock_result.output = None34 assert self.mock_result.get_output_str() == '-- No output --'35 def test_GetEditorLogStr_HasOutput_ReturnsCorrectly(self):36 self.mock_result.editor_log = 'expected log output'37 assert self.mock_result.get_editor_log_str() == 'expected log output'38 def test_GetEditorLogStr_NoOutput_ReturnsCorrectly(self):39 self.mock_result.editor_log = None40 assert self.mock_result.get_editor_log_str() == '-- No editor log found --'41class TestResultPass(unittest.TestCase):42 def test_Create_ValidArgs_CorrectAttributes(self):43 mock_test_spec = mock.MagicMock()44 mock_output = mock.MagicMock()45 mock_editor_log = mock.MagicMock()46 under_test = editor_test.Result.Pass(mock_test_spec, mock_output, mock_editor_log)47 assert under_test.test_spec == mock_test_spec48 assert under_test.output == mock_output49 assert under_test.editor_log == mock_editor_log50 def test_Str_ValidString_ReturnsOutput(self):51 mock_test_spec = mock.MagicMock()52 mock_output = 'mock_output'53 mock_editor_log = mock.MagicMock()54 under_test = editor_test.Result.Pass(mock_test_spec, mock_output, mock_editor_log)55 assert mock_output in str(under_test)56class TestResultFail(unittest.TestCase):57 def test_Create_ValidArgs_CorrectAttributes(self):58 mock_test_spec = mock.MagicMock()59 mock_output = mock.MagicMock()60 mock_editor_log = mock.MagicMock()61 under_test = editor_test.Result.Fail(mock_test_spec, mock_output, mock_editor_log)62 assert under_test.test_spec == mock_test_spec63 assert under_test.output == mock_output64 assert under_test.editor_log == mock_editor_log65 def test_Str_ValidString_ReturnsOutput(self):66 mock_test_spec = mock.MagicMock()67 mock_output = 'mock_output'68 mock_editor_log = 'mock_editor_log'69 under_test = editor_test.Result.Fail(mock_test_spec, mock_output, mock_editor_log)70 assert mock_output in str(under_test)71 assert mock_editor_log in str(under_test)72class TestResultCrash(unittest.TestCase):73 def test_Create_ValidArgs_CorrectAttributes(self):74 mock_test_spec = mock.MagicMock()75 mock_output = mock.MagicMock()76 mock_editor_log = mock.MagicMock()77 mock_ret_code = mock.MagicMock()78 mock_stacktrace = mock.MagicMock()79 under_test = editor_test.Result.Crash(mock_test_spec, mock_output, mock_ret_code, mock_stacktrace,80 mock_editor_log)81 assert under_test.test_spec == mock_test_spec82 assert under_test.output == mock_output83 assert under_test.editor_log == mock_editor_log84 assert under_test.ret_code == mock_ret_code85 assert under_test.stacktrace == mock_stacktrace86 def test_Str_ValidString_ReturnsOutput(self):87 mock_test_spec = mock.MagicMock()88 mock_output = 'mock_output'89 mock_editor_log = 'mock_editor_log'90 mock_return_code = 091 mock_stacktrace = 'mock stacktrace'92 under_test = editor_test.Result.Crash(mock_test_spec, mock_output, mock_return_code, mock_stacktrace,93 mock_editor_log)94 assert mock_stacktrace in str(under_test)95 assert mock_output in str(under_test)96 assert mock_editor_log in str(under_test)97 def test_Str_MissingStackTrace_ReturnsCorrectly(self):98 mock_test_spec = mock.MagicMock()99 mock_output = 'mock_output'100 mock_editor_log = 'mock_editor_log'101 mock_return_code = 0102 mock_stacktrace = None103 under_test = editor_test.Result.Crash(mock_test_spec, mock_output, mock_return_code, mock_stacktrace,104 mock_editor_log)105 assert mock_output in str(under_test)106 assert mock_editor_log in str(under_test)107class TestResultTimeout(unittest.TestCase):108 def test_Create_ValidArgs_CorrectAttributes(self):109 mock_test_spec = mock.MagicMock()110 mock_output = mock.MagicMock()111 mock_editor_log = mock.MagicMock()112 mock_timeout = mock.MagicMock()113 under_test = editor_test.Result.Timeout(mock_test_spec, mock_output, mock_timeout, mock_editor_log)114 assert under_test.test_spec == mock_test_spec115 assert under_test.output == mock_output116 assert under_test.editor_log == mock_editor_log117 assert under_test.time_secs == mock_timeout118 def test_Str_ValidString_ReturnsOutput(self):119 mock_test_spec = mock.MagicMock()120 mock_output = 'mock_output'121 mock_editor_log = 'mock_editor_log'122 mock_timeout = 0123 under_test = editor_test.Result.Timeout(mock_test_spec, mock_output, mock_timeout, mock_editor_log)124 assert mock_output in str(under_test)125 assert mock_editor_log in str(under_test)126class TestResultUnknown(unittest.TestCase):127 def test_Create_ValidArgs_CorrectAttributes(self):128 mock_test_spec = mock.MagicMock()129 mock_output = mock.MagicMock()130 mock_editor_log = mock.MagicMock()131 mock_extra_info = mock.MagicMock()132 under_test = editor_test.Result.Unknown(mock_test_spec, mock_output, mock_extra_info, mock_editor_log)133 assert under_test.test_spec == mock_test_spec134 assert under_test.output == mock_output135 assert under_test.editor_log == mock_editor_log136 assert under_test.extra_info == mock_extra_info137 def test_Str_ValidString_ReturnsOutput(self):138 mock_test_spec = mock.MagicMock()139 mock_output = 'mock_output'140 mock_editor_log = 'mock_editor_log'141 mock_extra_info = 'mock extra info'142 under_test = editor_test.Result.Unknown(mock_test_spec, mock_output, mock_extra_info, mock_editor_log)143 assert mock_output in str(under_test)144 assert mock_editor_log in str(under_test)145class TestEditorTestSuite(unittest.TestCase):146 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')147 def test_EditorTestData_ValidAP_TeardownAPOnce(self, mock_kill_processes):148 mock_editor_test_suite = editor_test.EditorTestSuite()149 mock_test_data_generator = mock_editor_test_suite._editor_test_data(mock.MagicMock())150 mock_asset_processor = mock.MagicMock()151 for test_data in mock_test_data_generator:152 test_data.asset_processor = mock_asset_processor153 mock_asset_processor.stop.assert_called_once_with(1)154 mock_asset_processor.teardown.assert_called()155 assert test_data.asset_processor is None156 mock_kill_processes.assert_called_once_with(include_asset_processor=True)157 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')158 def test_EditorTestData_NoAP_NoTeardownAP(self, mock_kill_processes):159 mock_editor_test_suite = editor_test.EditorTestSuite()160 mock_test_data_generator = mock_editor_test_suite._editor_test_data(mock.MagicMock())161 for test_data in mock_test_data_generator:162 test_data.asset_processor = None163 mock_kill_processes.assert_called_once_with(include_asset_processor=False)164 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite.filter_session_shared_tests')165 def test_PytestCustomModifyItems_FunctionsMatch_AddsRunners(self, mock_filter_tests):166 class MockTestSuite(editor_test.EditorTestSuite):167 pass168 mock_func_1 = mock.MagicMock()169 mock_test = mock.MagicMock()170 runner_1 = editor_test.EditorTestSuite.Runner('mock_runner_1', mock_func_1, [mock_test])171 mock_run_pytest_func = mock.MagicMock()172 runner_1.run_pytestfunc = mock_run_pytest_func173 mock_result_pytestfuncs = [mock.MagicMock()]174 runner_1.result_pytestfuncs = mock_result_pytestfuncs175 mock_items = []176 mock_items.extend(mock_result_pytestfuncs)177 MockTestSuite._runners = [runner_1]178 mock_test_1 = mock.MagicMock()179 mock_test_2 = mock.MagicMock()180 mock_filter_tests.return_value = [mock_test_1, mock_test_2]181 MockTestSuite.pytest_custom_modify_items(mock.MagicMock(), mock_items, mock.MagicMock())182 assert mock_items == [mock_run_pytest_func, mock_result_pytestfuncs[0]]183 def test_GetSingleTests_NoSingleTests_EmptyList(self):184 class MockTestSuite(editor_test.EditorTestSuite):185 pass186 mock_test_suite = MockTestSuite()187 tests = mock_test_suite.get_single_tests()188 assert len(tests) == 0189 def test_GetSingleTests_OneSingleTests_ReturnsOne(self):190 class MockTestSuite(editor_test.EditorTestSuite):191 class MockSingleTest(editor_test.EditorSingleTest):192 pass193 mock_test_suite = MockTestSuite()194 tests = mock_test_suite.get_single_tests()195 assert len(tests) == 1196 assert tests[0].__name__ == "MockSingleTest"197 assert issubclass(tests[0], editor_test.EditorSingleTest)198 def test_GetSingleTests_AllTests_ReturnsOnlySingles(self):199 class MockTestSuite(editor_test.EditorTestSuite):200 class MockSingleTest(editor_test.EditorSingleTest):201 pass202 class MockAnotherSingleTest(editor_test.EditorSingleTest):203 pass204 class MockNotSingleTest(editor_test.EditorSharedTest):205 pass206 mock_test_suite = MockTestSuite()207 tests = mock_test_suite.get_single_tests()208 assert len(tests) == 2209 for test in tests:210 assert issubclass(test, editor_test.EditorSingleTest)211 def test_GetSharedTests_NoSharedTests_EmptyList(self):212 class MockTestSuite(editor_test.EditorTestSuite):213 pass214 mock_test_suite = MockTestSuite()215 tests = mock_test_suite.get_shared_tests()216 assert len(tests) == 0217 def test_GetSharedTests_OneSharedTests_ReturnsOne(self):218 class MockTestSuite(editor_test.EditorTestSuite):219 class MockSharedTest(editor_test.EditorSharedTest):220 pass221 mock_test_suite = MockTestSuite()222 tests = mock_test_suite.get_shared_tests()223 assert len(tests) == 1224 assert tests[0].__name__ == 'MockSharedTest'225 assert issubclass(tests[0], editor_test.EditorSharedTest)226 def test_GetSharedTests_AllTests_ReturnsOnlyShared(self):227 class MockTestSuite(editor_test.EditorTestSuite):228 class MockSharedTest(editor_test.EditorSharedTest):229 pass230 class MockAnotherSharedTest(editor_test.EditorSharedTest):231 pass232 class MockNotSharedTest(editor_test.EditorSingleTest):233 pass234 mock_test_suite = MockTestSuite()235 tests = mock_test_suite.get_shared_tests()236 assert len(tests) == 2237 for test in tests:238 assert issubclass(test, editor_test.EditorSharedTest)239 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite.filter_session_shared_tests')240 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite.get_shared_tests')241 def test_GetSessionSharedTests_Valid_CallsCorrectly(self, mock_get_shared_tests, mock_filter_session):242 editor_test.EditorTestSuite.get_session_shared_tests(mock.MagicMock())243 assert mock_get_shared_tests.called244 assert mock_filter_session.called245 @mock.patch('ly_test_tools.o3de.editor_test.skipping_pytest_runtest_setup', mock.MagicMock())246 def test_FilterSessionSharedTests_OneSharedTest_ReturnsOne(self):247 def mock_test():248 pass249 mock_test.originalname = 'mock_test'250 mock_test.__name__ = mock_test.originalname251 mock_session_items = [mock_test]252 mock_shared_tests = [mock_test]253 selected_tests = editor_test.EditorTestSuite.filter_session_shared_tests(mock_session_items, mock_shared_tests)254 assert selected_tests == mock_session_items255 assert len(selected_tests) == 1256 @mock.patch('ly_test_tools.o3de.editor_test.skipping_pytest_runtest_setup', mock.MagicMock())257 def test_FilterSessionSharedTests_ManyTests_ReturnsCorrectTests(self):258 def mock_test():259 pass260 def mock_test_2():261 pass262 def mock_test_3():263 pass264 mock_test.originalname = 'mock_test'265 mock_test.__name__ = mock_test.originalname266 mock_test_2.originalname = 'mock_test_2'267 mock_test_2.__name__ = mock_test_2.originalname268 mock_test_3.originalname = 'mock_test_3'269 mock_test_3.__name__ = mock_test_3.originalname270 mock_session_items = [mock_test, mock_test_2]271 mock_shared_tests = [mock_test, mock_test_2, mock_test_3]272 selected_tests = editor_test.EditorTestSuite.filter_session_shared_tests(mock_session_items, mock_shared_tests)273 assert selected_tests == mock_session_items274 @mock.patch('ly_test_tools.o3de.editor_test.skipping_pytest_runtest_setup')275 def test_FilterSessionSharedTests_SkipOneTest_ReturnsCorrectTests(self, mock_skip):276 def mock_test():277 pass278 def mock_test_2():279 pass280 def mock_test_3():281 pass282 mock_skip.side_effect = [True, Exception]283 mock_test.originalname = 'mock_test'284 mock_test.__name__ = mock_test.originalname285 mock_test_2.originalname = 'mock_test_2'286 mock_test_2.__name__ = mock_test_2.originalname287 mock_test_3.originalname = 'mock_test_3'288 mock_test_3.__name__ = mock_test_3.originalname289 mock_session_items = [mock_test, mock_test_2]290 mock_shared_tests = [mock_test, mock_test_2, mock_test_3]291 selected_tests = editor_test.EditorTestSuite.filter_session_shared_tests(mock_session_items, mock_shared_tests)292 assert selected_tests == [mock_test]293 @mock.patch('ly_test_tools.o3de.editor_test.skipping_pytest_runtest_setup', mock.MagicMock(side_effect=Exception))294 def test_FilterSessionSharedTests_ExceptionDuringSkipSetup_SkipsAddingTest(self):295 def mock_test():296 pass297 mock_test.originalname = 'mock_test'298 mock_test.__name__ = mock_test.originalname299 mock_session_items = [mock_test]300 mock_shared_tests = [mock_test]301 selected_tests = editor_test.EditorTestSuite.filter_session_shared_tests(mock_session_items, mock_shared_tests)302 assert len(selected_tests) == 0303 def test_FilterSharedTests_TrueParams_ReturnsTrueTests(self):304 mock_test = mock.MagicMock()305 mock_test.is_batchable = True306 mock_test.is_parallelizable = True307 mock_test_2 = mock.MagicMock()308 mock_test_2.is_batchable = False309 mock_test_2.is_parallelizable = False310 mock_shared_tests = [mock_test, mock_test_2]311 filtered_tests = editor_test.EditorTestSuite.filter_shared_tests(312 mock_shared_tests, is_batchable=True, is_parallelizable=True)313 assert filtered_tests == [mock_test]314 def test_FilterSharedTests_FalseParams_ReturnsFalseTests(self):315 mock_test = mock.MagicMock()316 mock_test.is_batchable = True317 mock_test.is_parallelizable = True318 mock_test_2 = mock.MagicMock()319 mock_test_2.is_batchable = False320 mock_test_2.is_parallelizable = False321 mock_shared_tests = [mock_test, mock_test_2]322 filtered_tests = editor_test.EditorTestSuite.filter_shared_tests(323 mock_shared_tests, is_batchable=False, is_parallelizable=False)324 assert filtered_tests == [mock_test_2]325class TestUtils(unittest.TestCase):326 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')327 def test_PrepareAssetProcessor_APExists_StartsAP(self, mock_kill_processes):328 mock_test_suite = editor_test.EditorTestSuite()329 mock_workspace = mock.MagicMock()330 mock_editor_data = mock.MagicMock()331 mock_ap = mock.MagicMock()332 mock_editor_data.asset_processor = mock_ap333 mock_test_suite._prepare_asset_processor(mock_workspace, mock_editor_data)334 assert mock_ap.start.called335 assert not mock_kill_processes.called336 @mock.patch('ly_test_tools.o3de.asset_processor.AssetProcessor.start')337 @mock.patch('ly_test_tools.environment.process_utils.process_exists')338 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')339 def test_PrepareAssetProcessor_NoAP_KillAndCreateAP(self, mock_kill_processes, mock_proc_exists, mock_start):340 mock_test_suite = editor_test.EditorTestSuite()341 mock_workspace = mock.MagicMock()342 mock_editor_data = mock.MagicMock()343 mock_editor_data.asset_processor = None344 mock_proc_exists.return_value = False345 mock_test_suite._prepare_asset_processor(mock_workspace, mock_editor_data)346 mock_kill_processes.assert_called_with(include_asset_processor=True)347 assert isinstance(mock_editor_data.asset_processor, ly_test_tools.o3de.asset_processor.AssetProcessor)348 assert mock_start.called349 @mock.patch('ly_test_tools.o3de.asset_processor.AssetProcessor.start')350 @mock.patch('ly_test_tools.environment.process_utils.process_exists')351 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')352 def test_PrepareAssetProcessor_NoAPButProcExists_NoKill(self, mock_kill_processes, mock_proc_exists, mock_start):353 mock_test_suite = editor_test.EditorTestSuite()354 mock_workspace = mock.MagicMock()355 mock_editor_data = mock.MagicMock()356 mock_editor_data.asset_processor = None357 mock_proc_exists.return_value = True358 mock_test_suite._prepare_asset_processor(mock_workspace, mock_editor_data)359 mock_kill_processes.assert_called_with(include_asset_processor=False)360 assert not mock_start.called361 assert mock_editor_data.asset_processor is None362 @mock.patch('ly_test_tools.o3de.asset_processor.AssetProcessor.start')363 @mock.patch('ly_test_tools.environment.process_utils.process_exists')364 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')365 def test_PrepareAssetProcessor_NoAPButProcExists_NoKill(self, mock_kill_processes, mock_proc_exists, mock_start):366 mock_test_suite = editor_test.EditorTestSuite()367 mock_workspace = mock.MagicMock()368 mock_editor_data = mock.MagicMock()369 mock_editor_data.asset_processor = None370 mock_proc_exists.return_value = True371 mock_test_suite._prepare_asset_processor(mock_workspace, mock_editor_data)372 mock_kill_processes.assert_called_with(include_asset_processor=False)373 assert not mock_start.called374 assert mock_editor_data.asset_processor is None375 @mock.patch('ly_test_tools.o3de.editor_test_utils.kill_all_ly_processes')376 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._prepare_asset_processor')377 def test_SetupEditorTest_ValidArgs_CallsCorrectly(self, mock_prepare_ap, mock_kill_processes):378 mock_test_suite = editor_test.EditorTestSuite()379 mock_editor = mock.MagicMock()380 mock_test_suite._setup_editor_test(mock_editor, mock.MagicMock(), mock.MagicMock())381 assert mock_editor.configure_settings.called382 assert mock_prepare_ap.called383 mock_kill_processes.assert_called_once_with(include_asset_processor=False)384 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_module_filename')385 def test_GetResultsUsingOutput_ValidJsonSuccess_CreatesPassResult(self, mock_get_module):386 mock_get_module.return_value = 'mock_module_name'387 mock_test_suite = editor_test.EditorTestSuite()388 mock_test = mock.MagicMock()389 mock_test.__name__ = 'mock_test_name'390 mock_test_list = [mock_test]391 mock_output = 'JSON_START(' \392 '{"name": "mock_module_name", "output": "mock_std_out", "success": "mock_success_data"}' \393 ')JSON_END'394 results = mock_test_suite._get_results_using_output(mock_test_list, mock_output, '')395 assert len(results) == 1396 assert 'mock_test_name' in results.keys()397 assert isinstance(results['mock_test_name'], editor_test.Result.Pass)398 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_module_filename')399 def test_GetResultsUsingOutput_ValidJsonFail_CreatesFailResult(self, mock_get_module):400 mock_get_module.return_value = 'mock_module_name'401 mock_test_suite = editor_test.EditorTestSuite()402 mock_test = mock.MagicMock()403 mock_test.__name__ = 'mock_test_name'404 mock_test_list = [mock_test]405 mock_output = 'JSON_START(' \406 '{"name": "mock_module_name", "output": "mock_std_out", "failed": "mock_fail_data", "success": ""}' \407 ')JSON_END'408 results = mock_test_suite._get_results_using_output(mock_test_list, mock_output, '')409 assert len(results) == 1410 assert 'mock_test_name' in results.keys()411 assert isinstance(results['mock_test_name'], editor_test.Result.Fail)412 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_module_filename')413 def test_GetResultsUsingOutput_ModuleNotInLog_CreatesUnknownResult(self, mock_get_module):414 mock_get_module.return_value = 'different_module_name'415 mock_test_suite = editor_test.EditorTestSuite()416 mock_test = mock.MagicMock()417 mock_test.__name__ = 'mock_test_name'418 mock_test_list = [mock_test]419 mock_output = 'JSON_START(' \420 '{"name": "mock_module_name", "output": "mock_std_out", "failed": "mock_fail_data"}' \421 ')JSON_END'422 results = mock_test_suite._get_results_using_output(mock_test_list, mock_output, '')423 assert len(results) == 1424 assert 'mock_test_name' in results.keys()425 assert isinstance(results['mock_test_name'], editor_test.Result.Unknown)426 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_module_filename')427 def test_GetResultsUsingOutput_MultipleTests_CreatesCorrectResults(self, mock_get_module):428 mock_get_module.side_effect = ['mock_module_name_pass', 'mock_module_name_fail', 'different_module_name']429 mock_test_suite = editor_test.EditorTestSuite()430 mock_test_pass = mock.MagicMock()431 mock_test_pass.__name__ = 'mock_test_name_pass'432 mock_test_fail = mock.MagicMock()433 mock_test_fail.__name__ = 'mock_test_name_fail'434 mock_test_unknown = mock.MagicMock()435 mock_test_unknown.__name__ = 'mock_test_name_unknown'436 mock_test_list = [mock_test_pass, mock_test_fail, mock_test_unknown]437 mock_output = 'JSON_START(' \438 '{"name": "mock_module_name_pass", "output": "mock_std_out", "success": "mock_success_data"}' \439 ')JSON_END' \440 'JSON_START(' \441 '{"name": "mock_module_name_fail", "output": "mock_std_out", "failed": "mock_fail_data", "success": ""}' \442 ')JSON_END' \443 'JSON_START(' \444 '{"name": "mock_module_name_unknown", "output": "mock_std_out", "failed": "mock_fail_data", "success": ""}' \445 ')JSON_END'446 mock_editor_log = 'JSON_START(' \447 '{"name": "mock_module_name_pass"}' \448 ')JSON_END' \449 'JSON_START(' \450 '{"name": "mock_module_name_fail"}' \451 ')JSON_END'452 results = mock_test_suite._get_results_using_output(mock_test_list, mock_output, mock_editor_log)453 assert len(results) == 3454 assert 'mock_test_name_pass' in results.keys()455 assert 'mock_test_name_fail' in results.keys()456 assert 'mock_test_name_unknown' in results.keys()457 assert isinstance(results['mock_test_name_pass'], editor_test.Result.Pass)458 assert isinstance(results['mock_test_name_fail'], editor_test.Result.Fail)459 assert isinstance(results['mock_test_name_unknown'], editor_test.Result.Unknown)460 @mock.patch('builtins.print')461 def test_ReportResult_TestPassed_ReportsCorrectly(self, mock_print):462 mock_test_name = 'mock name'463 mock_pass = ly_test_tools.o3de.editor_test.Result.Pass("", "", "")464 ly_test_tools.o3de.editor_test.EditorTestSuite._report_result(mock_test_name, mock_pass)465 mock_print.assert_called_with(f'Test {mock_test_name}:\nTest Passed\n------------\n| Output |\n------------\n'466 f'-- No output --\n')467 @mock.patch('pytest.fail')468 def test_ReportResult_TestFailed_FailsCorrectly(self, mock_pytest_fail):469 mock_fail = ly_test_tools.o3de.editor_test.Result.Fail("", "", "")470 ly_test_tools.o3de.editor_test.EditorTestSuite._report_result('mock_test_name', mock_fail)471 mock_pytest_fail.assert_called_with('Test mock_test_name:\nTest FAILED\n------------\n| Output |'472 '\n------------\n-- No output --\n--------------\n| Editor log |'473 '\n--------------\n-- No editor log found --\n')474class TestRunningTests(unittest.TestCase):475 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')476 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')477 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')478 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')479 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')480 @mock.patch('os.path.join', mock.MagicMock())481 def test_ExecEditorTest_TestSucceeds_ReturnsPass(self, mock_cycle_crash, mock_get_testcase_filepath,482 mock_retrieve_log, mock_retrieve_editor_log,483 mock_get_output_results):484 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()485 mock_workspace = mock.MagicMock()486 mock_workspace.paths.engine_root.return_value = ""487 mock_editor = mock.MagicMock()488 mock_test_spec = mock.MagicMock()489 mock_test_spec.__name__ = 'mock_test_name'490 mock_editor.get_returncode.return_value = 0491 mock_get_output_results.return_value = {}492 results = mock_test_suite._exec_editor_test(mock.MagicMock(), mock_workspace, mock_editor, 0,493 'mock_log_name', mock_test_spec, [])494 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Pass)495 assert mock_cycle_crash.called496 assert mock_editor.start.called497 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')498 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')499 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')500 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')501 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')502 @mock.patch('os.path.join', mock.MagicMock())503 def test_ExecEditorTest_TestFails_ReturnsFail(self, mock_cycle_crash, mock_get_testcase_filepath,504 mock_retrieve_log, mock_retrieve_editor_log,505 mock_get_output_results):506 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()507 mock_workspace = mock.MagicMock()508 mock_workspace.paths.engine_root.return_value = ""509 mock_editor = mock.MagicMock()510 mock_test_spec = mock.MagicMock()511 mock_test_spec.__name__ = 'mock_test_name'512 mock_editor.get_returncode.return_value = 15513 mock_get_output_results.return_value = {}514 results = mock_test_suite._exec_editor_test(mock.MagicMock(), mock_workspace, mock_editor, 0,515 'mock_log_name', mock_test_spec, [])516 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Fail)517 assert mock_cycle_crash.called518 assert mock_editor.start.called519 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_crash_output')520 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')521 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')522 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')523 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')524 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')525 @mock.patch('os.path.join', mock.MagicMock())526 @mock.patch('os.path.basename', mock.MagicMock())527 def test_ExecEditorTest_TestCrashes_ReturnsCrash(self, mock_cycle_crash, mock_get_testcase_filepath,528 mock_retrieve_log, mock_retrieve_editor_log,529 mock_get_output_results, mock_retrieve_crash):530 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()531 mock_workspace = mock.MagicMock()532 mock_workspace.paths.engine_root.return_value = ""533 mock_editor = mock.MagicMock()534 mock_test_spec = mock.MagicMock()535 mock_test_spec.__name__ = 'mock_test_name'536 mock_editor.get_returncode.return_value = 1537 mock_get_output_results.return_value = {}538 results = mock_test_suite._exec_editor_test(mock.MagicMock(), mock_workspace, mock_editor, 0,539 'mock_log_name', mock_test_spec, [])540 assert mock_cycle_crash.call_count == 2541 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Crash)542 assert mock_editor.start.called543 assert mock_retrieve_crash.called544 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')545 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')546 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')547 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')548 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')549 def test_ExecEditorTest_TestTimeout_ReturnsTimeout(self, mock_cycle_crash, mock_get_testcase_filepath,550 mock_retrieve_log, mock_retrieve_editor_log,551 mock_get_output_results):552 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()553 mock_workspace = mock.MagicMock()554 mock_workspace.paths.engine_root.return_value = ""555 mock_editor = mock.MagicMock()556 mock_test_spec = mock.MagicMock()557 mock_test_spec.__name__ = 'mock_test_name'558 mock_editor.wait.side_effect = ly_test_tools.launchers.exceptions.WaitTimeoutError()559 mock_get_output_results.return_value = {}560 results = mock_test_suite._exec_editor_test(mock.MagicMock(), mock_workspace, mock_editor, 0,561 'mock_log_name', mock_test_spec, [])562 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Timeout)563 assert mock_cycle_crash.called564 assert mock_editor.start.called565 assert mock_editor.stop.called566 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')567 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')568 @mock.patch('os.path.join', mock.MagicMock())569 @mock.patch('os.path.splitext', mock.MagicMock())570 def test_ExecEditorMultitest_AllTestsPass_ReturnsPasses(self, mock_cycle_crash, mock_get_filepath):571 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()572 mock_workspace = mock.MagicMock()573 mock_artifact_manager = mock.MagicMock()574 mock_artifact_manager.save_artifact.return_value = mock.MagicMock()575 mock_workspace.artifact_manager = mock_artifact_manager576 mock_workspace.paths.engine_root.return_value = ""577 mock_editor = mock.MagicMock()578 mock_editor.get_returncode.return_value = 0579 mock_test_spec = mock.MagicMock()580 mock_test_spec.__name__ = 'mock_test_name'581 mock_test_spec_2 = mock.MagicMock()582 mock_test_spec_2.__name__ = 'mock_test_name_2'583 mock_test_spec_list = [mock_test_spec, mock_test_spec_2]584 mock_get_filepath.return_value = ""585 results = mock_test_suite._exec_editor_multitest(mock.MagicMock(), mock_workspace, mock_editor, 0,586 'mock_log_name', mock_test_spec_list, [])587 assert len(results) == 2588 assert isinstance(results['mock_test_name'], editor_test.Result.Pass)589 assert isinstance(results['mock_test_name_2'], editor_test.Result.Pass)590 assert mock_cycle_crash.called591 assert mock_get_filepath.called592 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')593 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')594 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')595 @mock.patch('os.path.join', mock.MagicMock())596 @mock.patch('os.path.splitext', mock.MagicMock())597 def test_ExecEditorMultitest_OneFailure_CallsCorrectFunc(self, mock_cycle_crash, mock_get_testcase_filepath,598 mock_get_results):599 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()600 mock_workspace = mock.MagicMock()601 mock_workspace.paths.engine_root.return_value = ""602 mock_editor = mock.MagicMock()603 mock_editor.get_returncode.return_value = 15604 mock_test_spec = mock.MagicMock()605 mock_test_spec_2 = mock.MagicMock()606 mock_test_spec_list = [mock_test_spec, mock_test_spec_2]607 mock_get_testcase_filepath.side_effect = ['mock_path', 'mock_path_2']608 mock_get_results.return_value = {'mock_test_name': mock.MagicMock(), 'mock_test_name_2': mock.MagicMock()}609 results = mock_test_suite._exec_editor_multitest(mock.MagicMock(), mock_workspace, mock_editor, 0,610 'mock_log_name', mock_test_spec_list, [])611 assert len(results) == 2612 assert mock_cycle_crash.called613 assert mock_get_results.called614 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_crash_output')615 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')616 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')617 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')618 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')619 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')620 @mock.patch('os.path.join', mock.MagicMock())621 @mock.patch('os.path.basename', mock.MagicMock())622 def test_ExecEditorMultitest_OneCrash_ReportsOnUnknownResult(self, mock_cycle_crash, mock_get_testcase_filepath,623 mock_retrieve_log, mock_retrieve_editor_log,624 mock_get_results, mock_retrieve_crash):625 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()626 mock_workspace = mock.MagicMock()627 mock_workspace.paths.engine_root.return_value = ""628 mock_editor = mock.MagicMock()629 mock_editor.get_returncode.return_value = 1630 mock_test_spec = mock.MagicMock()631 mock_test_spec.__name__ = 'mock_test_name'632 mock_test_spec_2 = mock.MagicMock()633 mock_test_spec_2.__name__ = 'mock_test_name_2'634 mock_test_spec_list = [mock_test_spec, mock_test_spec_2]635 mock_unknown_result = ly_test_tools.o3de.editor_test.Result.Unknown(test_spec=None)636 mock_unknown_result.test_spec = mock.MagicMock()637 mock_unknown_result.editor_log = mock.MagicMock()638 mock_get_testcase_filepath.side_effect = ['mock_path', 'mock_path_2']639 mock_get_results.return_value = {mock_test_spec.__name__: mock_unknown_result,640 mock_test_spec_2.__name__: mock.MagicMock()}641 results = mock_test_suite._exec_editor_multitest(mock.MagicMock(), mock_workspace, mock_editor, 0,642 'mock_log_name', mock_test_spec_list, [])643 assert mock_cycle_crash.call_count == 2644 assert mock_get_results.called645 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Crash)646 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_crash_output')647 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')648 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')649 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')650 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')651 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')652 @mock.patch('os.path.join', mock.MagicMock())653 @mock.patch('os.path.basename', mock.MagicMock())654 def test_ExecEditorMultitest_ManyUnknown_ReportsUnknownResults(self, mock_cycle_crash, mock_get_testcase_filepath,655 mock_retrieve_log, mock_retrieve_editor_log,656 mock_get_results, mock_retrieve_crash):657 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()658 mock_workspace = mock.MagicMock()659 mock_workspace.paths.engine_root.return_value = ""660 mock_editor = mock.MagicMock()661 mock_editor.get_returncode.return_value = 1662 mock_test_spec = mock.MagicMock()663 mock_test_spec.__name__ = 'mock_test_name'664 mock_test_spec_2 = mock.MagicMock()665 mock_test_spec_2.__name__ = 'mock_test_name_2'666 mock_test_spec_list = [mock_test_spec, mock_test_spec_2]667 mock_unknown_result = ly_test_tools.o3de.editor_test.Result.Unknown(test_spec=None)668 mock_unknown_result.__name__ = 'mock_test_name'669 mock_unknown_result.test_spec = mock.MagicMock()670 mock_unknown_result.test_spec.__name__ = 'mock_test_spec_name'671 mock_unknown_result.editor_log = mock.MagicMock()672 mock_get_testcase_filepath.side_effect = ['mock_path', 'mock_path_2']673 mock_get_results.return_value = {mock_test_spec.__name__: mock_unknown_result,674 mock_test_spec_2.__name__: mock_unknown_result}675 results = mock_test_suite._exec_editor_multitest(mock.MagicMock(), mock_workspace, mock_editor, 0,676 'mock_log_name', mock_test_spec_list, [])677 assert mock_cycle_crash.call_count == 2678 assert mock_get_results.called679 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Crash)680 assert isinstance(results[mock_test_spec_2.__name__], editor_test.Result.Unknown)681 assert results[mock_test_spec_2.__name__].extra_info, "Extra info missing from Unknown failure"682 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_results_using_output')683 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_editor_log_content')684 @mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')685 @mock.patch('ly_test_tools.o3de.editor_test_utils.get_testcase_module_filepath')686 @mock.patch('ly_test_tools.o3de.editor_test_utils.cycle_crash_report')687 def test_ExecEditorMultitest_EditorTimeout_ReportsCorrectly(self, mock_cycle_crash, mock_get_testcase_filepath,688 mock_retrieve_log, mock_retrieve_editor_log,689 mock_get_results):690 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()691 mock_workspace = mock.MagicMock()692 mock_workspace.paths.engine_root.return_value = ""693 mock_editor = mock.MagicMock()694 mock_editor.wait.side_effect = ly_test_tools.launchers.exceptions.WaitTimeoutError()695 mock_test_spec = mock.MagicMock()696 mock_test_spec.__name__ = 'mock_test_name'697 mock_test_spec_2 = mock.MagicMock()698 mock_test_spec_2.__name__ = 'mock_test_name_2'699 mock_test_spec_list = [mock_test_spec, mock_test_spec_2]700 mock_unknown_result = ly_test_tools.o3de.editor_test.Result.Unknown(test_spec=None)701 mock_unknown_result.test_spec = mock.MagicMock()702 mock_unknown_result.test_spec.__name__ = 'mock_test_spec_name'703 mock_unknown_result.output = mock.MagicMock()704 mock_unknown_result.editor_log = mock.MagicMock()705 mock_get_testcase_filepath.side_effect = ['mock_path', 'mock_path_2']706 mock_get_results.return_value = {mock_test_spec.__name__: mock_unknown_result,707 mock_test_spec_2.__name__: mock_unknown_result}708 results = mock_test_suite._exec_editor_multitest(mock.MagicMock(), mock_workspace, mock_editor, 0,709 'mock_log_name', mock_test_spec_list, [])710 assert mock_cycle_crash.called711 assert mock_get_results.called712 assert isinstance(results[mock_test_spec.__name__], editor_test.Result.Timeout)713 assert isinstance(results[mock_test_spec_2.__name__], editor_test.Result.Unknown)714 assert results[mock_test_spec_2.__name__].extra_info, "Extra info missing from Unknown failure"715 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._report_result')716 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._exec_editor_test')717 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')718 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())719 def test_RunSingleTest_ValidTest_ReportsResults(self, mock_setup_test, mock_exec_editor_test, mock_report_result):720 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()721 mock_test_data = mock.MagicMock()722 mock_test_spec = mock.MagicMock()723 mock_result = mock.MagicMock()724 mock_test_name = 'mock_test_result'725 mock_exec_editor_test.return_value = {mock_test_name: mock_result}726 mock_test_suite._run_single_test(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock_test_data,727 mock_test_spec)728 assert mock_setup_test.called729 assert mock_exec_editor_test.called730 assert mock_test_data.results.update.called731 mock_report_result.assert_called_with(mock_test_name, mock_result)732 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._exec_editor_multitest')733 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')734 def test_RunBatchedTests_ValidTests_CallsCorrectly(self, mock_setup_test, mock_exec_multitest):735 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()736 mock_test_data = mock.MagicMock()737 mock_test_suite._run_batched_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock_test_data,738 mock.MagicMock(), [])739 assert mock_setup_test.called740 assert mock_exec_multitest.called741 assert mock_test_data.results.update.called742 @mock.patch('threading.Thread')743 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_number_parallel_editors')744 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')745 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())746 def test_RunParallelTests_TwoTestsAndEditors_TwoThreads(self, mock_setup_test, mock_get_num_editors, mock_thread):747 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()748 mock_get_num_editors.return_value = 2749 mock_test_spec_list = [mock.MagicMock(), mock.MagicMock()]750 mock_test_data = mock.MagicMock()751 mock_test_suite._run_parallel_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock_test_data,752 mock_test_spec_list, [])753 assert mock_setup_test.called754 assert mock_test_data.results.update.call_count == len(mock_test_spec_list)755 assert mock_thread.call_count == len(mock_test_spec_list)756 @mock.patch('threading.Thread')757 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_number_parallel_editors')758 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')759 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())760 def test_RunParallelTests_TenTestsAndTwoEditors_TenThreads(self, mock_setup_test, mock_get_num_editors, mock_thread):761 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()762 mock_get_num_editors.return_value = 2763 mock_test_spec_list = []764 for i in range(10):765 mock_test_spec_list.append(mock.MagicMock())766 mock_test_data = mock.MagicMock()767 mock_test_suite._run_parallel_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock_test_data,768 mock_test_spec_list, [])769 assert mock_setup_test.called770 assert mock_test_data.results.update.call_count == len(mock_test_spec_list)771 assert mock_thread.call_count == len(mock_test_spec_list)772 @mock.patch('threading.Thread')773 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_number_parallel_editors')774 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')775 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())776 def test_RunParallelTests_TenTestsAndThreeEditors_TenThreads(self, mock_setup_test, mock_get_num_editors,777 mock_thread):778 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()779 mock_get_num_editors.return_value = 3780 mock_test_spec_list = []781 for i in range(10):782 mock_test_spec_list.append(mock.MagicMock())783 mock_test_data = mock.MagicMock()784 mock_test_suite._run_parallel_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock_test_data,785 mock_test_spec_list, [])786 assert mock_setup_test.called787 assert mock_test_data.results.update.call_count == len(mock_test_spec_list)788 assert mock_thread.call_count == len(mock_test_spec_list)789 @mock.patch('threading.Thread')790 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_number_parallel_editors')791 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')792 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())793 def test_RunParallelBatchedTests_TwoTestsAndEditors_TwoThreads(self, mock_setup_test, mock_get_num_editors,794 mock_thread):795 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()796 mock_get_num_editors.return_value = 2797 mock_test_spec_list = [mock.MagicMock(), mock.MagicMock()]798 mock_test_data = mock.MagicMock()799 mock_test_suite._run_parallel_batched_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(),800 mock_test_data, mock_test_spec_list, [])801 assert mock_setup_test.called802 assert mock_test_data.results.update.call_count == len(mock_test_spec_list)803 assert mock_thread.call_count == len(mock_test_spec_list)804 @mock.patch('threading.Thread')805 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_number_parallel_editors')806 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')807 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())808 def test_RunParallelBatchedTests_TenTestsAndTwoEditors_2Threads(self, mock_setup_test, mock_get_num_editors,809 mock_thread):810 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()811 mock_get_num_editors.return_value = 2812 mock_test_spec_list = []813 for i in range(10):814 mock_test_spec_list.append(mock.MagicMock())815 mock_test_data = mock.MagicMock()816 mock_test_suite._run_parallel_batched_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(),817 mock_test_data, mock_test_spec_list, [])818 assert mock_setup_test.called819 assert mock_test_data.results.update.call_count == 2820 assert mock_thread.call_count == 2821 @mock.patch('threading.Thread')822 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._get_number_parallel_editors')823 @mock.patch('ly_test_tools.o3de.editor_test.EditorTestSuite._setup_editor_test')824 @mock.patch('ly_test_tools.o3de.editor_test_utils.save_failed_asset_joblogs', mock.MagicMock())825 def test_RunParallelBatchedTests_TenTestsAndThreeEditors_ThreeThreads(self, mock_setup_test, mock_get_num_editors,826 mock_thread):827 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()828 mock_get_num_editors.return_value = 3829 mock_test_spec_list = []830 for i in range(10):831 mock_test_spec_list.append(mock.MagicMock())832 mock_test_data = mock.MagicMock()833 mock_test_suite._run_parallel_batched_tests(mock.MagicMock(), mock.MagicMock(), mock.MagicMock(),834 mock_test_data, mock_test_spec_list, [])835 assert mock_setup_test.called836 assert mock_test_data.results.update.call_count == 3837 assert mock_thread.call_count == 3838 def test_GetNumberParallelEditors_ConfigExists_ReturnsConfig(self):839 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()840 mock_request = mock.MagicMock()841 mock_request.config.getoption.return_value = 1842 num_of_editors = mock_test_suite._get_number_parallel_editors(mock_request)843 assert num_of_editors == 1844 def test_GetNumberParallelEditors_ConfigNotExists_ReturnsDefault(self):845 mock_test_suite = ly_test_tools.o3de.editor_test.EditorTestSuite()846 mock_request = mock.MagicMock()847 mock_request.config.getoption.return_value = None848 num_of_editors = mock_test_suite._get_number_parallel_editors(mock_request)849 assert num_of_editors == mock_test_suite.get_number_parallel_editors()850@mock.patch('_pytest.python.Class.collect')851class TestEditorTestClass(unittest.TestCase):852 def setUp(self):853 mock_name = mock.MagicMock()854 mock_collector = mock.MagicMock()855 self.mock_test_class = ly_test_tools.o3de.editor_test.EditorTestSuite.EditorTestClass(mock_name, mock_collector)856 self.mock_test_class.obj = mock.MagicMock()857 single_1 = mock.MagicMock()858 single_1.__name__ = 'single_1_name'859 single_2 = mock.MagicMock()860 single_2.__name__ = 'single_2_name'861 self.mock_test_class.obj.get_single_tests.return_value = [single_1, single_2]862 batch_1 = mock.MagicMock()863 batch_1.__name__ = 'batch_1_name'864 batch_2 = mock.MagicMock()865 batch_2.__name__ = 'batch_2_name'866 parallel_1 = mock.MagicMock()867 parallel_1.__name__ = 'parallel_1_name'868 parallel_2 = mock.MagicMock()869 parallel_2.__name__ = 'parallel_2_name'870 both_1 = mock.MagicMock()871 both_1.__name__ = 'both_1_name'872 both_2 = mock.MagicMock()873 both_2.__name__ = 'both_2_name'874 self.mock_test_class.obj.filter_shared_tests.side_effect = [ [batch_1, batch_2],875 [parallel_1, parallel_2],876 [both_1, both_2] ]877 def test_Collect_NoParallelNoBatched_RunsAsSingleTests(self, mock_collect):878 self.mock_test_class.config.getoption.return_value = True879 self.mock_test_class.collect()880 assert self.mock_test_class.obj.single_1_name.__name__ == 'single_run'881 assert self.mock_test_class.obj.single_2_name.__name__ == 'single_run'882 assert self.mock_test_class.obj.batch_1_name.__name__ == 'single_run'883 assert self.mock_test_class.obj.batch_2_name.__name__ == 'single_run'884 assert self.mock_test_class.obj.parallel_1_name.__name__ == 'single_run'885 assert self.mock_test_class.obj.parallel_2_name.__name__ == 'single_run'886 assert self.mock_test_class.obj.both_1_name.__name__ == 'single_run'887 assert self.mock_test_class.obj.both_2_name.__name__ == 'single_run'888 def test_Collect_AllValidTests_RunsAsInteded(self, mock_collect):889 self.mock_test_class.config.getoption.return_value = False890 self.mock_test_class.collect()891 assert self.mock_test_class.obj.single_1_name.__name__ == 'single_run'892 assert self.mock_test_class.obj.single_2_name.__name__ == 'single_run'893 assert self.mock_test_class.obj.batch_1_name.__name__ == 'result'894 assert self.mock_test_class.obj.batch_2_name.__name__ == 'result'895 assert self.mock_test_class.obj.parallel_1_name.__name__ == 'result'896 assert self.mock_test_class.obj.parallel_2_name.__name__ == 'result'897 assert self.mock_test_class.obj.both_1_name.__name__ == 'result'898 assert self.mock_test_class.obj.both_2_name.__name__ == 'result'899 def test_Collect_AllValidTests_CallsCollect(self, mock_collect):900 self.mock_test_class.collect()901 assert mock_collect.called902 def test_Collect_NormalCollection_ReturnsFilteredRuns(self, mock_collect):903 mock_run = mock.MagicMock()904 mock_run.obj.marks = {"run_type": 'run_shared'}905 mock_run_2 = mock.MagicMock()906 mock_run_2.obj.marks = {"run_type": 'result'}907 mock_instance = mock.MagicMock()908 mock_instance.collect.return_value = [mock_run, mock_run_2]909 mock_collect.return_value = [mock_instance]910 collection = self.mock_test_class.collect()911 assert collection == [mock_run_2]912 def test_Collect_NormalRun_ReturnsRunners(self, mock_collect):913 self.mock_test_class.collect()914 runners = self.mock_test_class.obj._runners915 assert runners[0].name == 'run_batched_tests'916 assert runners[1].name == 'run_parallel_tests'917 assert runners[2].name == 'run_parallel_batched_tests'918 def test_Collect_NormalCollection_StoresRunners(self, mock_collect):919 mock_runner = mock.MagicMock()920 mock_run = mock.MagicMock()921 mock_run.obj.marks = {"run_type": 'run_shared'}922 mock_run.function.marks = {"runner": mock_runner}923 mock_runner_2 = mock.MagicMock()924 mock_runner_2.result_pytestfuncs = []925 mock_run_2 = mock.MagicMock()926 mock_run_2.obj.marks = {"run_type": 'result'}927 mock_run_2.function.marks = {"runner": mock_runner_2}928 mock_instance = mock.MagicMock()929 mock_instance.collect.return_value = [mock_run, mock_run_2]930 mock_collect.return_value = [mock_instance]931 self.mock_test_class.collect()932 assert mock_runner.run_pytestfunc == mock_run...

Full Screen

Full Screen

test_jira.py

Source:test_jira.py Github

copy

Full Screen

...124 except Exception:125 pass126 config.set('Jira', 'enabled', 'true')127 # Execute method with jira annotation128 MockTestClass().mock_test_pass()129 # Check jira status130 expected_status = {'TOOLIUM-1': ('TOOLIUM-1', 'Pass', None, [])}131 assert expected_status == jira.jira_tests_status132def test_jira_annotation_fail(logger):133 # Configure jira module134 config = DriverWrappersPool.get_default_wrapper().config135 try:136 config.add_section('Jira')137 except Exception:138 pass139 config.set('Jira', 'enabled', 'true')140 # Execute method with jira annotation141 with pytest.raises(AssertionError):142 MockTestClass().mock_test_fail()143 # Check jira status144 expected_status = {'TOOLIUM-3': ('TOOLIUM-3', 'Fail', "The test 'test name' has failed: test error", [])}145 assert expected_status == jira.jira_tests_status146def test_jira_annotation_multiple(logger):147 # Configure jira module148 config = DriverWrappersPool.get_default_wrapper().config149 try:150 config.add_section('Jira')151 except Exception:152 pass153 config.set('Jira', 'enabled', 'true')154 # Execute methods with jira annotation155 MockTestClass().mock_test_pass()156 with pytest.raises(AssertionError):157 MockTestClass().mock_test_fail()158 MockTestClass().mock_test_pass_2()159 # Check jira status160 expected_status = {'TOOLIUM-1': ('TOOLIUM-1', 'Pass', None, []),161 'TOOLIUM-3': ('TOOLIUM-3', 'Fail', "The test 'test name' has failed: test error", []),162 'TOOLIUM-2': ('TOOLIUM-2', 'Pass', None, [])}163 assert expected_status == jira.jira_tests_status164def test_jira_disabled(logger):165 # Configure jira module166 config = DriverWrappersPool.get_default_wrapper().config167 try:168 config.add_section('Jira')169 except Exception:170 pass171 config.set('Jira', 'enabled', 'false')172 # Execute method with jira annotation173 MockTestClass().mock_test_pass()174 # Check jira status175 expected_status = {}176 assert expected_status == jira.jira_tests_status177class MockTestClass():178 def get_method_name(self):179 return 'test name'180 @jira.jira(test_key='TOOLIUM-1')181 def mock_test_pass(self):182 pass183 @jira.jira(test_key='TOOLIUM-2')184 def mock_test_pass_2(self):185 pass186 @jira.jira(test_key='TOOLIUM-3')187 def mock_test_fail(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful