Skip to content

Commit ff028ee

Browse files
Add TestClass parsing to XML parser (#347)
1 parent 95b5e74 commit ff028ee

5 files changed

Lines changed: 16 additions & 8 deletions

File tree

docs/internals/extensions/source_code_linker.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_feature():
9292
1. **XML Parsing** (`xml_parser.py`)
9393
- Scans `bazel-testlogs/` for `test.xml` files.
9494
- Parses test cases and extracts:
95-
- Name
95+
- Name & Classname
9696
- File path
9797
- Line
9898
- Result (e.g. passed, failed, skipped)
@@ -104,6 +104,8 @@ def test_feature():
104104
- `DataFromTestCase` (used for external needs)
105105
- `DataForTestLink` (used for linking tests to requirements)
106106

107+
> If there is a Classname then it gets combined with the function name for the displayed link as follows: `Classname__Functionname`
108+
107109
2. **Need Linking**
108110
- Generates external Sphinx needs from `DataFromTestCase`.
109111
- Creates `testlink` attributes on linked requirements.

src/extensions/score_source_code_linker/tests/expected_grouped.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"TestLinks": [
2323
{
24-
"name": "test_system_startup_time",
24+
"name": "TestRequirementsCoverage__test_system_startup_time",
2525
"file": "src/tests/testfile_2.py",
2626
"line": 25,
2727
"need": "TREQ_ID_1",

src/extensions/score_source_code_linker/tests/expected_testlink.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"result_text": ""
3737
},
3838
{
39-
"name": "test_system_startup_time",
39+
"name": "TestRequirementsCoverage__test_system_startup_time",
4040
"file": "src/tests/testfile_2.py",
4141
"line": 25,
4242
"need": "TREQ_ID_1",

src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def example_test_link_text_all_ok(sphinx_base_dir: Path):
339339
return {
340340
"TREQ_ID_1": [
341341
DataForTestLink(
342-
name="test_system_startup_time",
342+
name="TestRequirementsCoverage__test_system_startup_time",
343343
file=Path("src/tests/testfile_2.py"),
344344
need="TREQ_ID_1",
345345
line=25,

src/extensions/score_source_code_linker/xml_parser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,17 @@ def read_test_xml_file(file: Path) -> tuple[list[DataOfTestCase], list[str]]:
104104
for testsuite in root.findall("testsuite"):
105105
for testcase in testsuite.findall("testcase"):
106106
case_properties = {}
107-
testname = testcase.get("name")
108-
assert testname is not None, (
109-
f"Testcase: {testcase} does not have a 'name' attribute. "
110-
"This is mandatory. This should not happen, something is wrong."
107+
testcasename = testcase.get("name", "")
108+
testclassname = testcase.get("classname", "")
109+
assert testclassname or testcasename, (
110+
f"Testcase: {testcase} does not have a 'name' or 'classname' attribute."
111+
"One of which is mandatory. This should not happen, something is wrong."
111112
)
113+
if testclassname:
114+
testcn = testclassname.split(".")[-1]
115+
testname = "__".join([testcn, testcasename])
116+
else:
117+
testname = testcasename
112118
test_file = testcase.get("file")
113119
line = testcase.get("line")
114120

0 commit comments

Comments
 (0)