conftest.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import json
  9. from pathlib import Path
  10. import pytest
  11. import uuid
  12. BUILD_INFO_KEY = 'build_info'
  13. CONFIG_PATH_KEY = 'config'
  14. BINARY_PATH_KEY = 'runtime_bin'
  15. COMMON_CONFIG_KEY = "common"
  16. JENKINS_KEY = "jenkins"
  17. RUNTIME_BIN_KEY = "runtime_bin"
  18. ENABLED_KEY = "enabled"
  19. WORKSPACE_KEY = "workspace"
  20. ROOT_KEY = "root"
  21. TEMP_KEY = "temp"
  22. REPO_KEY = "repo"
  23. RELATIVE_PATHS_KEY = "relative_paths"
  24. HISTORIC_KEY = 'historic'
  25. HISTORIC_SEQUENCES_KEY = "historic_sequences"
  26. ACTIVE_KEY = "active"
  27. HISTORIC_KEY = "historic"
  28. TEST_IMPACT_DATA_FILE_KEY = "test_impact_data_file"
  29. PREVIOUS_TEST_RUN_DATA_FILE_KEY = "previous_test_run_data_file"
  30. LAST_COMMIT_HASH_KEY = "last_commit_hash"
  31. COVERAGE_DATA_KEY = "coverage_data"
  32. PREVIOUS_TEST_RUNS_KEY = "previous_test_runs"
  33. HISTORIC_DATA_FILE_KEY = "data"
  34. REPORT_KEY = "reports"
  35. @pytest.fixture
  36. def test_data_file(build_directory):
  37. path = Path(build_directory+"/ly_test_impact_test_data.json")
  38. with open(path) as file:
  39. return json.load(file)
  40. @pytest.fixture(params=[pytest.param('profile', marks=pytest.mark.skipif("False")), pytest.param('debug', marks=pytest.mark.skipif("True"))])
  41. def build_type(request):
  42. """
  43. # debug build type disabled as we can't support testing this in AR as debug is not built
  44. """
  45. return request.param
  46. @pytest.fixture
  47. def storage_config(runtime_type, config_data):
  48. args_from_config = {}
  49. args_from_config['active_workspace'] = config_data[runtime_type][WORKSPACE_KEY][ACTIVE_KEY][ROOT_KEY]
  50. args_from_config['historic_workspace'] = config_data[runtime_type][WORKSPACE_KEY][HISTORIC_KEY][ROOT_KEY]
  51. args_from_config['unpacked_coverage_data_file'] = config_data[runtime_type][
  52. WORKSPACE_KEY][ACTIVE_KEY][RELATIVE_PATHS_KEY][TEST_IMPACT_DATA_FILE_KEY]
  53. args_from_config['previous_test_run_data_file'] = config_data[runtime_type][WORKSPACE_KEY][
  54. ACTIVE_KEY][RELATIVE_PATHS_KEY][PREVIOUS_TEST_RUN_DATA_FILE_KEY]
  55. args_from_config['historic_data_file'] = config_data[runtime_type][WORKSPACE_KEY][
  56. HISTORIC_KEY][RELATIVE_PATHS_KEY][HISTORIC_DATA_FILE_KEY]
  57. args_from_config['temp_workspace'] = config_data[runtime_type][WORKSPACE_KEY][TEMP_KEY][ROOT_KEY]
  58. return args_from_config
  59. @pytest.fixture
  60. def skip_if_test_targets_disabled(runtime_type, config_data):
  61. tiaf_bin = Path(config_data[runtime_type][RUNTIME_BIN_KEY])
  62. # We need the runtime to be enabled and the runtime binary to exist to run tests
  63. if not config_data[runtime_type][JENKINS_KEY][ENABLED_KEY] or not tiaf_bin.is_file():
  64. pytest.skip("Test targets are disabled for this runtime, test will be skipped.")
  65. @pytest.fixture
  66. def config_path(build_type, test_data_file):
  67. return test_data_file[BUILD_INFO_KEY][build_type][CONFIG_PATH_KEY]
  68. @pytest.fixture
  69. def binary_path(config_data, runtime_type):
  70. return config_data[runtime_type][BINARY_PATH_KEY]
  71. @pytest.fixture()
  72. def report_path(runtime_type, config_data, mock_uuid):
  73. return config_data[runtime_type][WORKSPACE_KEY][TEMP_KEY][REPORT_KEY]+"\\report."+mock_uuid.hex+".json"
  74. @pytest.fixture
  75. def config_data(config_path):
  76. with open(config_path) as f:
  77. return json.load(f)
  78. @pytest.fixture
  79. def tiaf_args(config_path):
  80. args = {}
  81. args['config'] = config_path
  82. args['src_branch'] = "123"
  83. args['dst_branch'] = "123"
  84. args['commit'] = "foobar"
  85. args['build_number'] = 1
  86. args['suites'] = "main"
  87. args['test_failure_policy'] = "continue"
  88. return args
  89. @pytest.fixture
  90. def main_args(tiaf_args, runtime_type, request):
  91. tiaf_args['runtime_type'] = runtime_type
  92. return tiaf_args
  93. @pytest.fixture(params=["native", "python"])
  94. def runtime_type(request):
  95. return request.param
  96. @pytest.fixture
  97. def mock_runtime(mocker):
  98. return mocker.patch('subprocess.run')
  99. @pytest.fixture(autouse=True)
  100. def mock_uuid(mocker):
  101. universal_uuid = uuid.uuid4()
  102. mocker.patch('uuid.uuid4', return_value=universal_uuid)
  103. return universal_uuid
  104. @pytest.fixture
  105. def default_runtime_args(mock_uuid, report_path):
  106. runtime_args = {}
  107. runtime_args['sequence'] = "--sequence=seed"
  108. runtime_args['test_failure_policy'] = "--fpolicy=continue"
  109. runtime_args['report'] = "--report=" + \
  110. str(report_path).replace("/", "\\")
  111. runtime_args['suites'] = "--suites=main"
  112. return runtime_args
  113. @pytest.fixture
  114. def cpp_default_runtime_args(default_runtime_args):
  115. return default_runtime_args