Skip to content

Commit

Permalink
Merge branch 'mr/pmderodat/xunit-importer' into 'master'
Browse files Browse the repository at this point in the history
e3-convert-xunit: add handling for classname attributes

See merge request it/e3-testsuite!18
  • Loading branch information
pmderodat committed Jan 19, 2024
2 parents ebf7702 + 7d60fa8 commit 6295052
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/e3/testsuite/report/xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ def run(self, filename: str) -> None:
assert testcase.tag == "testcase"

testcase_name = testcase.attrib["name"]
classname = testcase.attrib.get("classname")
time_str = testcase.attrib.get("time")

result = TestResult(
self.get_test_name(testsuite_name, testcase_name)
self.get_test_name(
testsuite_name, testcase_name, classname
)
)
result.time = float(time_str) if time_str else None
status = TestStatus.PASS
Expand Down Expand Up @@ -273,15 +276,26 @@ def get_unique_test_name(self, test_name: str) -> str:
result = f"{test_name}.{next(counter)}"
return result

def get_test_name(self, testsuite_name: str, testcase_name: str) -> str:
def get_test_name(
self,
testsuite_name: str,
testcase_name: str,
classname: Optional[str] = None,
) -> str:
"""Combine xUnit testsuite/testcase names into a unique test name.
:param testsuite_name: Name associated with a xUnit <testsuite>
element.
:param testcase_name: Name associated with a xUnit <testcase> element.
:param classname: If applicable, name of the class that owns this
testcase.
"""
return self.get_unique_test_name(
self.slugify(testsuite_name) + "." + self.slugify(testcase_name)
".".join(
self.slugify(name)
for name in [testsuite_name, classname, testcase_name]
if name
)
)


Expand Down
7 changes: 7 additions & 0 deletions tests/tests/test_xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def test_import(tmp_path):
Some failure logging</failure>
</testcase>
<!-- Test handling of classname. -->
<testcase name="test_name" classname="MyClass">
</testcase>
</testsuite>
<!-- Test usage of XFAILs. -->
Expand Down Expand Up @@ -247,6 +251,7 @@ def test_import(tmp_path):
index = ReportIndex.read(results_dir)

assert sorted(index.entries) == [
"Normal.MyClass.test_name",
"Normal.Test2",
"Normal.Test2-e",
"Normal.Test2-e.1",
Expand Down Expand Up @@ -295,6 +300,8 @@ def check_log(test_name, log):
check("Normal.test-failure-message", Status.FAIL, "Some failure message")
check_log("Normal.test-failure-message", "Some failure logging")

check("Normal.MyClass.test_name", Status.PASS)

check("XFails.test-ok", Status.XPASS)

check("XFails.test-failure", Status.XFAIL)
Expand Down

0 comments on commit 6295052

Please sign in to comment.