diff --git a/tests/models/xctests/conftest.py b/tests/models/xctests/conftest.py index 3c6030b2..3ce1340b 100644 --- a/tests/models/xctests/conftest.py +++ b/tests/models/xctests/conftest.py @@ -1,5 +1,6 @@ import json import pathlib +from typing import Dict import pytest from codemagic.models.xctests.xcresult import ActionsInvocationRecord @@ -15,3 +16,15 @@ def action_invocations_record(mocks_dir) -> ActionsInvocationRecord: with (mocks_dir / "actions_invocation_record.json").open() as fd: data = json.load(fd) return ActionsInvocationRecord(data, pathlib.Path("Test.xcresult")) + + +@pytest.fixture +def test_results_summary_dict(mocks_dir) -> Dict: + mock_path = mocks_dir / "test_results_summary.json" + return json.loads(mock_path.read_text()) + + +@pytest.fixture +def test_results_tests_dict(mocks_dir) -> Dict: + mock_path = mocks_dir / "test_results_tests.json" + return json.loads(mock_path.read_text()) diff --git a/tests/models/xctests/converter/test_xcode_16_converter.py b/tests/models/xctests/converter/test_xcode_16_converter.py index 4a2de7be..1976bdb2 100644 --- a/tests/models/xctests/converter/test_xcode_16_converter.py +++ b/tests/models/xctests/converter/test_xcode_16_converter.py @@ -13,210 +13,6 @@ from codemagic.models.xctests.converter import Xcode16XcResultConverter -def _get_test_report_tests(_): - return { - "devices": [ - { - "architecture": "arm64", - "deviceId": "D4A58F38-8890-43BE-93F9-3D268010475D", - "deviceName": "iPhone SE (3rd generation)", - "modelName": "iPhone SE (3rd generation)", - "osVersion": "18.0", - "platform": "iOS Simulator", - }, - ], - "testNodes": [ - { - "children": [ - { - "children": [ - { - "children": [ - { - "duration": "0,0011s", - "name": "testDisabledExample()", - "nodeIdentifier": "banaanTests/testDisabledExample()", - "nodeType": "Test Case", - "result": "Passed", - }, - { - "duration": "0,00045s", - "name": "testExample()", - "nodeIdentifier": "banaanTests/testExample()", - "nodeType": "Test Case", - "result": "Passed", - }, - { - "children": [ - { - "name": 'banaanTests.swift:50: failed: caught error: "badInput"', - "nodeType": "Failure Message", - "result": "Failed", - }, - ], - "duration": "0,2s", - "name": "testExceptionExample()", - "nodeIdentifier": "banaanTests/testExceptionExample()", - "nodeType": "Test Case", - "result": "Failed", - }, - { - "children": [ - { - "name": "banaanTests.swift:44: failed - This won't make the cut", - "nodeType": "Failure Message", - "result": "Failed", - }, - ], - "duration": "0,002s", - "name": "testFailExample()", - "nodeIdentifier": "banaanTests/testFailExample()", - "nodeType": "Test Case", - "result": "Failed", - }, - { - "duration": "0,26s", - "name": "testPerformanceExample()", - "nodeIdentifier": "banaanTests/testPerformanceExample()", - "nodeType": "Test Case", - "result": "Passed", - }, - { - "children": [ - { - "name": "Test skipped - This test is skipped", - "nodeType": "Failure Message", - "result": "Skipped", - }, - ], - "duration": "0,0052s", - "name": "testSkippedExample()", - "nodeIdentifier": "banaanTests/testSkippedExample()", - "nodeType": "Test Case", - "result": "Skipped", - }, - ], - "name": "banaanTests", - "nodeType": "Test Suite", - "result": "Failed", - }, - ], - "name": "banaanTests", - "nodeType": "Unit test bundle", - "result": "Failed", - }, - { - "children": [ - { - "children": [ - { - "duration": "2s", - "name": "testUIExample()", - "nodeIdentifier": "banaanUITests/testUIExample()", - "nodeType": "Test Case", - "result": "Passed", - }, - { - "children": [ - { - "name": "banaanUITests.swift:40: failed - Bad UI", - "nodeType": "Failure Message", - "result": "Failed", - }, - ], - "duration": "3s", - "name": "testUIFailExample()", - "nodeIdentifier": "banaanUITests/testUIFailExample()", - "nodeType": "Test Case", - "result": "Failed", - }, - ], - "name": "banaanUITests", - "nodeType": "Test Suite", - "result": "Failed", - }, - ], - "name": "banaanUITests", - "nodeType": "UI test bundle", - "result": "Failed", - }, - ], - "name": "banaan", - "nodeType": "Test Plan", - "result": "Failed", - }, - ], - "testPlanConfigurations": [ - { - "configurationId": "1", - "configurationName": "Test Scheme Action", - }, - ], - } - - -def _get_test_report_summary(_): - return { - "devicesAndConfigurations": [ - { - "device": { - "architecture": "arm64", - "deviceId": "D4A58F38-8890-43BE-93F9-3D268010475D", - "deviceName": "iPhone SE (3rd generation)", - "modelName": "iPhone SE (3rd generation)", - "osVersion": "18.0", - "platform": "iOS Simulator", - }, - "expectedFailures": 0, - "failedTests": 3, - "passedTests": 4, - "skippedTests": 1, - "testPlanConfiguration": { - "configurationId": "1", - "configurationName": "Test Scheme Action", - }, - }, - ], - "environmentDescription": "banaan ยท Built with macOS 14.7", - "expectedFailures": 0, - "failedTests": 3, - "finishTime": 1728473305.128, - "passedTests": 4, - "result": "Failed", - "skippedTests": 1, - "startTime": 1728473222.071, - "statistics": [ - { - "subtitle": "1 test run", - "title": "1 test collected performance metrics", - }, - ], - "testFailures": [ - { - "failureText": 'failed: caught error: "badInput"', - "targetName": "banaanTests", - "testIdentifier": 3, - "testName": "testExceptionExample()", - }, - { - "failureText": "failed - This won't make the cut", - "targetName": "banaanTests", - "testIdentifier": 4, - "testName": "testFailExample()", - }, - { - "failureText": "failed - Bad UI", - "targetName": "banaanUITests", - "testIdentifier": 8, - "testName": "testUIFailExample()", - }, - ], - "title": "Test - banaan", - "topInsights": [], - "totalTestCount": 8, - } - - @pytest.fixture def expected_properties() -> List[Property]: return [ @@ -230,8 +26,14 @@ def expected_properties() -> List[Property]: ] -@mock.patch.object(XcResultTool, "get_test_report_tests", _get_test_report_tests) -@mock.patch.object(XcResultTool, "get_test_report_summary", _get_test_report_summary) +@pytest.fixture(autouse=True) +def patch_xcresulttool(test_results_summary_dict, test_results_tests_dict): + mock_tests = mock.patch.object(XcResultTool, "get_test_report_tests", lambda _: test_results_tests_dict) + mock_summary = mock.patch.object(XcResultTool, "get_test_report_summary", lambda _: test_results_summary_dict) + with mock_tests, mock_summary: + yield + + @mock.patch("codemagic.models.xctests.converter.datetime") def test_converter(mock_datetime, expected_properties): mock_datetime.fromtimestamp.return_value = datetime(2024, 10, 15, tzinfo=timezone.utc) diff --git a/tests/models/xctests/xcresult/test_xcode_16_xcresult.py b/tests/models/xctests/xcresult/test_xcode_16_xcresult.py index 202a14ab..b568de40 100644 --- a/tests/models/xctests/xcresult/test_xcode_16_xcresult.py +++ b/tests/models/xctests/xcresult/test_xcode_16_xcresult.py @@ -1,7 +1,3 @@ -import json -from typing import Dict - -import pytest from codemagic.models.xctests.xcresult import XcTestNode from codemagic.models.xctests.xcresult import XcTestNodeType from codemagic.models.xctests.xcresult.xcode_16_xcresult import XcConfiguration @@ -14,18 +10,6 @@ from codemagic.models.xctests.xcresult.xcode_16_xcresult import XcTestStatistic -@pytest.fixture -def test_results_summary_dict(mocks_dir) -> Dict: - mock_path = mocks_dir / "test_results_summary.json" - return json.loads(mock_path.read_text()) - - -@pytest.fixture -def test_results_tests_dict(mocks_dir) -> Dict: - mock_path = mocks_dir / "test_results_tests.json" - return json.loads(mock_path.read_text()) - - def test_load_test_results_summary(test_results_summary_dict): test_results_summary = XcSummary.from_dict(test_results_summary_dict)