2
0

conftest.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. pytest test configuration file for launching LoftSample.GameLauncher tests.
  6. """
  7. import logging
  8. import os
  9. import types
  10. import pytest
  11. import ly_test_tools.builtin.helpers as helpers
  12. import ly_test_tools.environment.file_system as file_system
  13. import ly_test_tools.log.log_monitor
  14. logger = logging.getLogger(__name__)
  15. @pytest.fixture(scope="function", autouse=True)
  16. def clean_loftsample_gamelauncher_logs(request, workspace):
  17. """Deletes any LoftSample log files so that the test run can start with empty logs."""
  18. logs = ['Game.log']
  19. logger.info(f'Deleting log files for LoftSample.GameLauncher tests: {logs}')
  20. for log in logs:
  21. log_file = os.path.join(workspace.paths.project_log(), log)
  22. if os.path.exists(log_file):
  23. file_system.delete(file_list=[log_file],
  24. del_files=True,
  25. del_dirs=False)
  26. @pytest.fixture(scope="function", autouse=True)
  27. def loftsample_gamelauncher_log_monitor(request, workspace):
  28. """Creates a LyTestTools log monitor object for monitoring LoftSample.GameLauncher logs."""
  29. def is_alive(launcher_name):
  30. return True
  31. launcher = ly_test_tools.launchers.platforms.base.Launcher(workspace, []) # Needed for log monitor to work.
  32. launcher.is_alive = types.MethodType(is_alive, launcher)
  33. file_to_monitor = os.path.join(workspace.paths.project_log(), 'Game.log')
  34. log_monitor = ly_test_tools.log.log_monitor.LogMonitor(launcher=launcher, log_file_path=file_to_monitor, log_creation_max_wait_time=40)
  35. log_monitor.file_to_monitor = file_to_monitor
  36. return log_monitor