diff --git a/docs/internals/extensions/source_code_linker.md b/docs/internals/extensions/source_code_linker.md index 51ba7690..2f53c840 100644 --- a/docs/internals/extensions/source_code_linker.md +++ b/docs/internals/extensions/source_code_linker.md @@ -92,7 +92,7 @@ def test_feature(): 1. **XML Parsing** (`xml_parser.py`) - Scans `bazel-testlogs/` for `test.xml` files. - Parses test cases and extracts: - - Name + - Name & Classname - File path - Line - Result (e.g. passed, failed, skipped) @@ -104,6 +104,8 @@ def test_feature(): - `DataFromTestCase` (used for external needs) - `DataForTestLink` (used for linking tests to requirements) +> If there is a Classname then it gets combined with the function name for the displayed link as follows: `Classname__Functionname` + 2. **Need Linking** - Generates external Sphinx needs from `DataFromTestCase`. - Creates `testlink` attributes on linked requirements. diff --git a/src/extensions/score_source_code_linker/tests/expected_grouped.json b/src/extensions/score_source_code_linker/tests/expected_grouped.json index da05343c..b5abf26c 100644 --- a/src/extensions/score_source_code_linker/tests/expected_grouped.json +++ b/src/extensions/score_source_code_linker/tests/expected_grouped.json @@ -21,7 +21,7 @@ ], "TestLinks": [ { - "name": "test_system_startup_time", + "name": "TestRequirementsCoverage__test_system_startup_time", "file": "src/tests/testfile_2.py", "line": 25, "need": "TREQ_ID_1", diff --git a/src/extensions/score_source_code_linker/tests/expected_testlink.json b/src/extensions/score_source_code_linker/tests/expected_testlink.json index 9dc32210..19068a4d 100644 --- a/src/extensions/score_source_code_linker/tests/expected_testlink.json +++ b/src/extensions/score_source_code_linker/tests/expected_testlink.json @@ -36,7 +36,7 @@ "result_text": "" }, { - "name": "test_system_startup_time", + "name": "TestRequirementsCoverage__test_system_startup_time", "file": "src/tests/testfile_2.py", "line": 25, "need": "TREQ_ID_1", diff --git a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py index 44ea35a6..a400ff77 100644 --- a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py +++ b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py @@ -339,7 +339,7 @@ def example_test_link_text_all_ok(sphinx_base_dir: Path): return { "TREQ_ID_1": [ DataForTestLink( - name="test_system_startup_time", + name="TestRequirementsCoverage__test_system_startup_time", file=Path("src/tests/testfile_2.py"), need="TREQ_ID_1", line=25, diff --git a/src/extensions/score_source_code_linker/xml_parser.py b/src/extensions/score_source_code_linker/xml_parser.py index 022168d2..93456971 100644 --- a/src/extensions/score_source_code_linker/xml_parser.py +++ b/src/extensions/score_source_code_linker/xml_parser.py @@ -104,11 +104,17 @@ def read_test_xml_file(file: Path) -> tuple[list[DataOfTestCase], list[str]]: for testsuite in root.findall("testsuite"): for testcase in testsuite.findall("testcase"): case_properties = {} - testname = testcase.get("name") - assert testname is not None, ( - f"Testcase: {testcase} does not have a 'name' attribute. " - "This is mandatory. This should not happen, something is wrong." + testcasename = testcase.get("name", "") + testclassname = testcase.get("classname", "") + assert testclassname or testcasename, ( + f"Testcase: {testcase} does not have a 'name' or 'classname' attribute." + "One of which is mandatory. This should not happen, something is wrong." ) + if testclassname: + testcn = testclassname.split(".")[-1] + testname = "__".join([testcn, testcasename]) + else: + testname = testcasename test_file = testcase.get("file") line = testcase.get("line")