diff --git a/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py b/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py index 0fa51066..5d9aef11 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py +++ b/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py @@ -131,7 +131,10 @@ def __parse_python_tests( and collection_type != CollectionType.MANDATORY ): suites[SuiteType.NO_COMMISSIONING].add_test_case(test_case) - elif collection_type != CollectionType.MANDATORY: + elif ( + python_test_type != PythonTestType.MANDATORY + and collection_type != CollectionType.MANDATORY + ): suites[SuiteType.LEGACY].add_test_case(test_case) return [s for s in list(suites.values()) if len(s.test_cases) != 0] diff --git a/test_collections/matter/sdk_tests/support/tests/python_tests/test_python_script/mandatory_tests_info.json b/test_collections/matter/sdk_tests/support/tests/python_tests/test_python_script/mandatory_tests_info.json new file mode 100644 index 00000000..a7cf30c3 --- /dev/null +++ b/test_collections/matter/sdk_tests/support/tests/python_tests/test_python_script/mandatory_tests_info.json @@ -0,0 +1,35 @@ +{ + "sdk_sha": "aabbccddeeff11223344556677889900", + "tests": [ + { + "class_name": "TC_SameClass", + "desc": "TC TC_SameClass description 1", + "function": "test_TC_SC_1_1", + "path": "sdk/TC_SameClass", + "pics": [], + "steps": [ + { + "description": "Step 1", + "expectation": "", + "is_commissioning": false, + "test_plan_number": 1 + } + ] + }, + { + "class_name": "TC_DeviceConformance", + "desc": "TC_IDM_10_2 description", + "function": "test_TC_IDM_10_2", + "path": "sdk/TC_DeviceConformance", + "pics": [], + "steps": [ + { + "description": "Run entire test", + "expectation": "", + "is_commissioning": false, + "test_plan_number": 1 + } + ] + } + ] +} diff --git a/test_collections/matter/sdk_tests/support/tests/python_tests/test_sdk_python_collection.py b/test_collections/matter/sdk_tests/support/tests/python_tests/test_sdk_python_collection.py index f85e544c..23c55b28 100644 --- a/test_collections/matter/sdk_tests/support/tests/python_tests/test_sdk_python_collection.py +++ b/test_collections/matter/sdk_tests/support/tests/python_tests/test_sdk_python_collection.py @@ -26,7 +26,10 @@ PythonCaseDeclaration, PythonCollectionDeclaration, ) -from ...python_testing.sdk_python_tests import sdk_python_test_collection +from ...python_testing.sdk_python_tests import ( + sdk_mandatory_python_test_collection, + sdk_python_test_collection, +) @pytest.fixture @@ -42,6 +45,23 @@ def python_test_collection() -> PythonCollectionDeclaration: return sdk_python_test_collection(folder, tests_file_path=test_sdk_python_path) +def _load_collections_from( + tests_file_path: Path, +) -> tuple[PythonCollectionDeclaration, PythonCollectionDeclaration]: + with mock.patch.object(Path, "exists", return_value=True), mock.patch( + "test_collections.matter.sdk_tests.support.models.sdk_test_folder.open", + new=mock.mock_open(read_data="unit-test-python-version"), + ): + folder = SDKTestFolder(path=tests_file_path, filename_pattern="TC_*") + non_mandatory = sdk_python_test_collection( + folder, tests_file_path=tests_file_path + ) + mandatory = sdk_mandatory_python_test_collection( + folder, tests_file_path=tests_file_path + ) + return non_mandatory, mandatory + + def test_sdk_python_test_collection( python_test_collection: PythonCollectionDeclaration, ) -> None: @@ -64,3 +84,27 @@ def test_automated_suite(python_test_collection: PythonCollectionDeclaration) -> type_count[test_case.test_type] += 1 assert type_count[MatterTestType.AUTOMATED] == expected_automated_test_cases + + +def test_mandatory_test_not_duplicated_across_collections() -> None: + """Regression test for issue #1087. + + A mandatory test case (e.g. TC_IDM_10_2) must be present in the + "Mandatory SDK Python Tests" collection only, and must not also be + duplicated into the "Old script format" (LEGACY) suite of the + non-mandatory "SDK Python Tests" collection. + """ + tests_file_path = ( + Path(__file__).parent / "test_python_script/mandatory_tests_info.json" + ) + non_mandatory_collection, mandatory_collection = _load_collections_from( + tests_file_path + ) + + for suite in non_mandatory_collection.test_suites.values(): + assert "TC_IDM_10_2" not in suite.test_cases + + mandatory_suite_name = "Python Testing Suite - Mandatories" + assert mandatory_suite_name in mandatory_collection.test_suites.keys() + mandatory_suite = mandatory_collection.test_suites[mandatory_suite_name] + assert "TC_IDM_10_2" in mandatory_suite.test_cases