test_regression.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Regression tests for the built-in fixtures.
  6. """
  7. import logging
  8. import os
  9. import pytest
  10. import ly_test_tools.environment.process_utils as process_utils
  11. import ly_test_tools.environment.file_system as file_system
  12. import ly_test_tools.environment.waiter as waiter
  13. from ly_test_tools import WINDOWS
  14. pytestmark = pytest.mark.SUITE_periodic
  15. logger = logging.getLogger(__name__)
  16. @pytest.fixture(scope="function")
  17. def editor_closed_checker(request):
  18. """
  19. Verifies that the Editor and AP processes have been terminated when the test ends.
  20. """
  21. test_name = request.node
  22. yield
  23. # The Editor fixture should've terminated the Editor and the AP processes
  24. processes = ['Editor', 'AssetProcessor']
  25. processes_found = []
  26. for process in processes:
  27. if process_utils.process_exists(process, True):
  28. processes_found.append(f"Process '{process}' should have been terminated by the fixture after the test"
  29. f" {test_name} finished.")
  30. process_utils.kill_processes_named(process, True)
  31. assert not processes_found, f"Editor fixture unexpectedly did not clean up open processes, processes still open: {processes_found}"
  32. @pytest.fixture(scope="function")
  33. def log_cleaner(workspace):
  34. """
  35. Removes Game and Editor logs before test execution
  36. """
  37. logs = ['Game.log', 'Editor.log']
  38. for log in logs:
  39. log_file = os.path.join(workspace.paths.project_log(), log)
  40. if os.path.exists(log_file):
  41. file_system.delete([log_file], True, False)
  42. @pytest.mark.usefixtures("automatic_process_killer")
  43. @pytest.mark.usefixtures("log_cleaner")
  44. @pytest.mark.parametrize("project", ["AutomatedTesting"])
  45. @pytest.mark.skipif(not WINDOWS, reason="Editor currently only functions on Windows")
  46. @pytest.mark.parametrize("launcher_platform", ['windows_editor'])
  47. class TestEditorFixture(object):
  48. def test_EditorNotClosed_FixtureStopsProcesses(self, editor_closed_checker, editor, launcher_platform):
  49. # Set autotest mode and disable GPU usage
  50. editor.args.extend(['-NullRenderer', '-autotest_mode'])
  51. log_file = os.path.join(editor.workspace.paths.project_log(), "Editor.log")
  52. editor.start()
  53. waiter.wait_for(lambda: os.path.exists(log_file), timeout=180) # time out increased due to bug SPEC-3175
  54. assert editor.is_alive()
  55. # This test doesn't call editor.stop() explicitly. Instead it uses the editor_closed_checker fixture to verify
  56. # that the editor fixture closes the editor and AP processes.