diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py index 481d73274f..212c862efd 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py @@ -34,6 +34,38 @@ class TestHelper: # JIRA: SPEC-2880 # general.idle_wait_frames(1) + @staticmethod + def create_level(level_name: str) -> bool: + """ + :param level_name: The name of the level to be created + :return: True if ECreateLevelResult returns 0, False otherwise with logging to report reason + """ + Report.info(f"Creating level {level_name}") + + # Use these hardcoded values to pass expected values for old terrain system until new create_level API is + # available + heightmap_resolution = 1024 + heightmap_meters_per_pixel = 1 + terrain_texture_resolution = 4096 + use_terrain = False + + result = general.create_level_no_prompt(level_name, heightmap_resolution, heightmap_meters_per_pixel, + terrain_texture_resolution, use_terrain) + + # Result codes are ECreateLevelResult defined in CryEdit.h + if result == 1: + Report.info(f"{level_name} level already exists") + elif result == 2: + Report.info("Failed to create directory") + elif result == 3: + Report.info("Directory length is too long") + elif result != 0: + Report.info("Unknown error, failed to create level") + else: + Report.info(f"{level_name} level created successfully") + + return result == 0 + @staticmethod def open_level(directory : str, level : str): # type: (str, str) -> None diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_Embedded_E2E.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_Embedded_E2E.py index 84c661873c..fa45e057e2 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_Embedded_E2E.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_Embedded_E2E.py @@ -72,9 +72,9 @@ def DynamicSliceInstanceSpawner_Embedded_E2E(): # 1) Create a new, temporary level lvl_name = "tmp_level" helper.init_idle() - level_created = general.create_level_no_prompt(lvl_name, 1024, 1, 4096, False) + level_created = helper.create_level(lvl_name) general.idle_wait(1.0) - Report.critical_result(Tests.level_created, level_created == 0) + Report.critical_result(Tests.level_created, level_created) general.set_current_view_position(512.0, 480.0, 38.0) # 2) Create a new entity with required vegetation area components and Script Canvas component for launcher test diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_External_E2E.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_External_E2E.py index de2554034f..2353095849 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_External_E2E.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/DynamicSliceInstanceSpawner_External_E2E.py @@ -73,9 +73,9 @@ def DynamicSliceInstanceSpawner_External_E2E(): # 1) Create a new, temporary level lvl_name = "tmp_level" helper.init_idle() - level_created = general.create_level_no_prompt(lvl_name, 1024, 1, 4096, False) + level_created = helper.create_level(lvl_name) general.idle_wait(1.0) - Report.critical_result(Tests.level_created, level_created == 0) + Report.critical_result(Tests.level_created, level_created) general.set_current_view_position(512.0, 480.0, 38.0) # 2) Create a new entity with required vegetation area components and switch the Vegetation Asset List Source diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/LayerBlender_E2E_Editor.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/LayerBlender_E2E_Editor.py index bf6501f469..130d56937b 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/LayerBlender_E2E_Editor.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/EditorScripts/LayerBlender_E2E_Editor.py @@ -76,9 +76,9 @@ def LayerBlender_E2E_Editor(): # 1) Create a new, temporary level lvl_name = "tmp_level" helper.init_idle() - level_created = general.create_level_no_prompt(lvl_name, 1024, 1, 4096, False) + level_created = helper.create_level(lvl_name) general.idle_wait(1.0) - Report.critical_result(Tests.level_created, level_created == 0) + Report.critical_result(Tests.level_created, level_created) general.set_current_view_position(500.49, 498.69, 46.66) general.set_current_view_rotation(-42.05, 0.00, -36.33) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Main_Optimized.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Main_Optimized.py index 2211c28060..673e40e397 100644 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Main_Optimized.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/TestSuite_Main_Optimized.py @@ -18,6 +18,17 @@ from ly_test_tools.o3de.editor_test import EditorSingleTest, EditorSharedTest, E class TestAutomation(EditorTestSuite): enable_prefab_system = False + + # Helpers for test asset cleanup + def cleanup_test_level(self, workspace): + file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "Levels", "tmp_level")], + True, True) + + def cleanup_test_slices(self, workspace): + file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "slices", + "TestSlice_1.slice")], True, True) + file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "slices", + "TestSlice_2.slice")], True, True) class test_DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks(EditorParallelTest): from .EditorScripts import DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks as test_module @@ -37,10 +48,7 @@ class TestAutomation(EditorTestSuite): class test_SpawnerSlices_SliceCreationAndVisibilityToggleWorks(EditorSingleTest): # Custom teardown to remove slice asset created during test def teardown(self, request, workspace, editor, editor_test_results, launcher_platform): - file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "slices", - "TestSlice_1.slice")], True, True) - file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "slices", - "TestSlice_2.slice")], True, True) + TestAutomation.cleanup_test_slices(self, workspace) from .EditorScripts import SpawnerSlices_SliceCreationAndVisibilityToggleWorks as test_module class test_AssetListCombiner_CombinedDescriptorsExpressInConfiguredArea(EditorParallelTest): @@ -148,29 +156,32 @@ class TestAutomation(EditorTestSuite): class test_SlopeFilter_ComponentAndOverrides_InstancesPlantOnValidSlopes(EditorParallelTest): from .EditorScripts import SlopeFilter_ComponentAndOverrides_InstancesPlantOnValidSlope as test_module - @pytest.mark.xfail(reason="Intermittently fails to create level") class test_DynamicSliceInstanceSpawner_Embedded_E2E_Editor(EditorSingleTest): from .EditorScripts import DynamicSliceInstanceSpawner_Embedded_E2E as test_module - # Custom teardown to remove test level created during test - def teardown(self, request, workspace, editor, editor_test_results, launcher_platform): - file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "Levels", "tmp_level")], - True, True) + # Custom setup/teardown to remove test level created during test + def setup(self, request, workspace, editor, editor_test_results, launcher_platform): + TestAutomation.cleanup_test_level(self, workspace) + + def teardown(self, request, workspace, editor, editor_test_results, launcher_platform): + TestAutomation.cleanup_test_level(self, workspace) - @pytest.mark.xfail(reason="Intermittently fails to create level") class test_DynamicSliceInstanceSpawner_External_E2E_Editor(EditorSingleTest): from .EditorScripts import DynamicSliceInstanceSpawner_External_E2E as test_module - # Custom teardown to remove test level created during test - def teardown(self, request, workspace, editor, editor_test_results, launcher_platform): - file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "Levels", "tmp_level")], - True, True) + # Custom setup/teardown to remove test level created during test + def setup(self, request, workspace, editor, editor_test_results, launcher_platform): + TestAutomation.cleanup_test_level(self, workspace) + + def teardown(self, request, workspace, editor, editor_test_results, launcher_platform): + TestAutomation.cleanup_test_level(self, workspace) - @pytest.mark.xfail(reason="Intermittently fails to create level") class test_LayerBlender_E2E_Editor(EditorSingleTest): from .EditorScripts import LayerBlender_E2E_Editor as test_module - # Custom teardown to remove test level created during test + # Custom setup/teardown to remove test level created during test + def setup(self, request, workspace, editor, editor_test_results, launcher_platform): + TestAutomation.cleanup_test_level(self, workspace) + def teardown(self, request, workspace, editor, editor_test_results, launcher_platform): - file_system.delete([os.path.join(workspace.paths.engine_root(), "AutomatedTesting", "Levels", "tmp_level")], - True, True) + TestAutomation.cleanup_test_level(self, workspace)