Skip to content

In JUnit XML reports, the timestamp attribute is not populated correctly for all subTests #567

@flukeborder

Description

@flukeborder

Hello,

I have been experimenting with nose2 JUnit XML output plugin in conjunction with unittest subTest context manager and found that the timestamp attribute is populated correctly only for the first generated testcase node. For the subsequent nodes, the timestamp is set to '1970-01-01T00:00:00'.

A trivial example:

class SubTestReportTest(unittest.TestCase):
    def test_subtests(self):
        for cnt in range(10):
            with self.subTest("Testing cnt = {}".format(cnt), cnt=cnt):
                self.assertLess(cnt, 4, "Verify that the cnt is < 4")

... yields the following XML output:

<testsuite errors="0" failures="6" name="nose2-junit" skipped="0" tests="1" time="0.001">
  <testcase classname="__main__.SubTestReportTest" name="test_subtests [Testing cnt = 4] (cnt=4)" time="0.000497" timestamp="2023-04-05T09:54:42.927951">
    <failure message="test failure">Traceback (most recent call last):
  File "./test_reports.py", line 47, in test_subtests
    self.assertLess(cnt, 4, "Verify that the cnt is &lt; 4")
AssertionError: 4 not less than 4 : Verify that the cnt is &lt; 4
</failure>
    <system-out />
  </testcase>
  <testcase classname="__main__.SubTestReportTest" name="test_subtests [Testing cnt = 5] (cnt=5)" time="0.000000" timestamp="1970-01-01T00:00:00">
    <failure message="test failure">Traceback (most recent call last):
  File "./test_reports.py", line 47, in test_subtests
    self.assertLess(cnt, 4, "Verify that the cnt is &lt; 4")
AssertionError: 5 not less than 4 : Verify that the cnt is &lt; 4
</failure>
    <system-out />
  </testcase>
  <testcase classname="__main__.SubTestReportTest" name="test_subtests [Testing cnt = 6] (cnt=6)" time="0.000000" timestamp="1970-01-01T00:00:00">
    <failure message="test failure">Traceback (most recent call last):
  File "./test_reports.py", line 47, in test_subtests
    self.assertLess(cnt, 4, "Verify that the cnt is &lt; 4")
AssertionError: 6 not less than 4 : Verify that the cnt is &lt; 4
</failure>
    <system-out />
  </testcase>
  <testcase classname="__main__.SubTestReportTest" name="test_subtests [Testing cnt = 7] (cnt=7)" time="0.000000" timestamp="1970-01-01T00:00:00">
    <failure message="test failure">Traceback (most recent call last):
  File "./test_reports.py", line 47, in test_subtests
    self.assertLess(cnt, 4, "Verify that the cnt is &lt; 4")
AssertionError: 7 not less than 4 : Verify that the cnt is &lt; 4
</failure>
    <system-out />
  </testcase>
  <testcase classname="__main__.SubTestReportTest" name="test_subtests [Testing cnt = 8] (cnt=8)" time="0.000000" timestamp="1970-01-01T00:00:00">
    <failure message="test failure">Traceback (most recent call last):
  File "./test_reports.py", line 47, in test_subtests
    self.assertLess(cnt, 4, "Verify that the cnt is &lt; 4")
AssertionError: 8 not less than 4 : Verify that the cnt is &lt; 4
</failure>
    <system-out />
  </testcase>
  <testcase classname="__main__.SubTestReportTest" name="test_subtests [Testing cnt = 9] (cnt=9)" time="0.000000" timestamp="1970-01-01T00:00:00">
    <failure message="test failure">Traceback (most recent call last):
  File "./test_reports.py", line 47, in test_subtests
    self.assertLess(cnt, 4, "Verify that the cnt is &lt; 4")
AssertionError: 9 not less than 4 : Verify that the cnt is &lt; 4
</failure>
    <system-out />
  </testcase>
</testsuite>

Ideally, the expected output would be for each failure report to be associated with a timestamp indicating when the failure occurred. Alternatively, it could be a timestamp taken when the test case containing the subTests was started.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions