Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libregrtest: junit-xml output doesn't support subTest #126237

Open
encukou opened this issue Oct 31, 2024 · 4 comments
Open

libregrtest: junit-xml output doesn't support subTest #126237

encukou opened this issue Oct 31, 2024 · 4 comments
Assignees
Labels
tests Tests in the Lib/test dir

Comments

@encukou
Copy link
Member

encukou commented Oct 31, 2024

Running the tests with --junit-xml, the result does not include subTest results, as RegressionTestResult in libregrtest.testresult does not implement addSubTest.

There's no standard XML schema for the test results (see testmoapp/junitxml), but I think multiple <error> elements in a <testcase> make sense

@sobolevn
Copy link
Member

sobolevn commented Nov 1, 2024

@encukou do you already work on this? Or can I take this over, please? :)

@encukou
Copy link
Member Author

encukou commented Nov 1, 2024

I just moved it out of my TODO list, thinking it might be fun for someone else :)
If you want, please do take over!

@sobolevn
Copy link
Member

sobolevn commented Nov 3, 2024

What happens now for a test like this:

    def test_broken_subtest(self):
        for x in [1, 2, 3]:
            with self.subTest(x=x):
                self.assertEqual(x, 0)

produces:

<testsuites tests="1" errors="0" failures="3"><testsuite start="2024-11-03 09:35:14.984110" tests="1" errors="0" failures="3"><testcase /></testsuite></testsuites>

If we comment # with self.subTest(x=x):, the output changes to:

<testsuites tests="1" errors="0" failures="1"><testsuite start="2024-11-03 09:34:09.426455" tests="1" errors="0" failures="1"><testcase name="test.test_typing.TypeVarTests.test_broken_subtest" status="run" result="completed" time="0.002489"><system-out /><system-err /><failure type="AssertionError" message="AssertionError: 1 != 0&#10;">Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 660, in run
    self._callTestMethod(testMethod)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 606, in _callTestMethod
    result = method()
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_typing.py", line 569, in test_broken_subtest
    self.assertEqual(x, 0)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 916, in assertEqual
    assertion_func(first, second, msg=msg)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 909, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 1 != 0
</failure></testcase></testsuite></testsuites>

Basically, we need to have multiple <failure> nodes inside <testcase> with .subTest calls.

@sobolevn
Copy link
Member

sobolevn commented Nov 3, 2024

I don't quite like that there are multiple <failure> and multiple <system-out> and <system-err> tags:

<testsuites tests="1" errors="0" failures="3"><testsuite start="2024-11-03 14:20:57.276683" tests="1" errors="0" failures="3"><testcase name="test.test_typing.TypeVarTests.test_broken_subtest" status="run" result="completed" time="0.004247"><system-out /><system-err /><failure type="AssertionError" message="AssertionError: 1 != 0&#10;">Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 556, in subTest
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_typing.py", line 570, in test_broken_subtest
    self.assertEqual(x, 0)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 916, in assertEqual
    assertion_func(first, second, msg=msg)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 909, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 1 != 0
</failure><system-out /><system-err /><failure type="AssertionError" message="AssertionError: 2 != 0&#10;">Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 556, in subTest
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_typing.py", line 570, in test_broken_subtest
    self.assertEqual(x, 0)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 916, in assertEqual
    assertion_func(first, second, msg=msg)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 909, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 2 != 0
</failure><system-out /><system-err /><failure type="AssertionError" message="AssertionError: 3 != 0&#10;">Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 556, in subTest
    yield
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_typing.py", line 570, in test_broken_subtest
    self.assertEqual(x, 0)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 916, in assertEqual
    assertion_func(first, second, msg=msg)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/unittest/case.py", line 909, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 3 != 0
</failure></testcase></testsuite></testsuites>

I think it would be hard to parse. Not sure that it is even supported.
See https://github.com/testmoapp/junitxml/blob/1bcb6fb8b620906ec001a2c8e7a7c8e7c563a64b/examples/junit-complete.xml#L99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

2 participants