From 84b04691bd1a9938ab7bf48f6f45ad950c28bd0b Mon Sep 17 00:00:00 2001 From: Boris Yakobowski Date: Wed, 8 May 2024 15:27:51 +0000 Subject: [PATCH 1/2] Log testsuite information into each testcase Fixes it/e3-testsuite#17 --- src/e3/testsuite/report/xunit.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/e3/testsuite/report/xunit.py b/src/e3/testsuite/report/xunit.py index 47f5539..d60d094 100644 --- a/src/e3/testsuite/report/xunit.py +++ b/src/e3/testsuite/report/xunit.py @@ -84,13 +84,9 @@ def dump_xunit_report(name: str, index: ReportIndex, filename: str) -> None: for test_name, entry in sorted(index.entries.items()): result = entry.load() - # The only class involved in testcases (that we know of in this - # testsuite framework) is the TestDriver subclass, but this is not - # useful for the report, so leave this dummy "e3-testsuite-driver" - # instead. - testcase = etree.Element( - "testcase", name=test_name, classname="e3-testsuite-driver" - ) + # We use the testsuite name for 'classname', as we don't really have + # something more useful to display anyway. + testcase = etree.Element("testcase", name=test_name, classname=name) testsuite.append(testcase) # Get the XUnit-equivalent status for this test and update the From 6df7c1a2879cc2cee6d86848d45d05642ca61607 Mon Sep 17 00:00:00 2001 From: Boris Yakobowski Date: Wed, 8 May 2024 19:29:25 +0200 Subject: [PATCH 2/2] Add test for --xunit-name option of e3-testsuite-report --- NEWS.md | 2 ++ tests/tests/test_report_display.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/NEWS.md b/NEWS.md index f0065ca..4af44fb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ * `e3-convert-xunit`: warn about dangling XFAILs annotations. * `DiffTestDriver`: tolerate missing baseline files when rewriting baselines. +* The `--xunit-name` argument of `e3-testsuite-report` is now used to + fill the `classname` information of each XUnit individual test report. 26.0 (2023-01-19) ================= diff --git a/tests/tests/test_report_display.py b/tests/tests/test_report_display.py index 904c4d1..37fa3fa 100644 --- a/tests/tests/test_report_display.py +++ b/tests/tests/test_report_display.py @@ -530,6 +530,41 @@ def test_xunit_output(tmp_path, capsys): ET.parse(xunit_file) +def test_xunit_name(tmp_path, capsys): + """Check that --xunit-name has the desired effect.""" + xunit_file = str(tmp_path / "xunit.xml") + testsuite_name = "mytestsuite" + run( + [create_result("foo", Status.PASS)], + [ + "--xunit-output", + xunit_file, + "--xunit-name", + testsuite_name, + str(tmp_path), + ], + tmp_path, + capsys, + ) + + xml = ET.parse(xunit_file) + root = xml.getroot() + + # Check the root node + assert root.tag == "testsuites" + assert root.get("name") == testsuite_name + + # Check the invididual testsuites + testsuites = xml.findall(".//testsuite") + assert len(testsuites) != 0 + assert all(e.get("name") == testsuite_name for e in testsuites) + + # Check the invidiual tests + tests = xml.findall(".//testcase") + assert len(tests) != 0 + assert all(e.get("classname") == testsuite_name for e in tests) + + def test_output_file(tmp_path, capsys): """Check that nothing is printed on stdout when output is a file.""" create_report(