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

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

Open
flukeborder opened this issue Apr 5, 2023 · 0 comments

Comments

@flukeborder
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant