diff options
author | Matt McDonald <mmcdonald@google.com> | 2022-08-29 10:12:02 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-08-29 10:13:40 -0700 |
commit | d1724595b6e1e5a23daee396e23e2e3e4ab4dd6a (patch) | |
tree | 17bd2ff26b927ce140d941c0c7e0ee8757e28863 | |
parent | b2336b25d66600049d261684d16c6416d11a49ee (diff) | |
download | absl-py-d1724595b6e1e5a23daee396e23e2e3e4ab4dd6a.tar.gz |
Output elapsed time duration values with millisecond precision
This change tweaks the formatting used for outputting elapsed time duration values for testsuite and testcase nodes in the XML output file produced by `TextAndXMLTestRunner` to allow for visibility down to milliseconds of precision.
This also aligns with C++ https://github.com/google/googletest
PiperOrigin-RevId: 470750030
Change-Id: If940033e0e44adf95ff3bf43125c185f438b8d8e
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | absl/testing/tests/xml_reporter_test.py | 10 | ||||
-rw-r--r-- | absl/testing/xml_reporter.py | 6 |
3 files changed, 10 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5464857..06a8ee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com). * (testing) Assertions `assertRaisesWithPredicateMatch` and `assertRaisesWithLiteralMatch` now capture the raised `Exception` for further analysis when used as a context manager. +* (testing) TextAndXMLTestRunner now produces time duration values with + millisecond precision in XML test result output. ## 1.2.0 (2022-07-18) diff --git a/absl/testing/tests/xml_reporter_test.py b/absl/testing/tests/xml_reporter_test.py index 0261f64..c0d43a6 100644 --- a/absl/testing/tests/xml_reporter_test.py +++ b/absl/testing/tests/xml_reporter_test.py @@ -64,12 +64,12 @@ def xml_escaped_exception_type(exception_type): OUTPUT_STRING = '\n'.join([ r'<\?xml version="1.0"\?>', ('<testsuites name="" tests="%(tests)d" failures="%(failures)d"' - ' errors="%(errors)d" time="%(run_time).1f" timestamp="%(start_time)s">'), + ' errors="%(errors)d" time="%(run_time).3f" timestamp="%(start_time)s">'), ('<testsuite name="%(suite_name)s" tests="%(tests)d"' - ' failures="%(failures)d" errors="%(errors)d" time="%(run_time).1f"' + ' failures="%(failures)d" errors="%(errors)d" time="%(run_time).3f"' ' timestamp="%(start_time)s">'), (' <testcase name="%(test_name)s" status="%(status)s" result="%(result)s"' - ' time="%(run_time).1f" classname="%(classname)s"' + ' time="%(run_time).3f" classname="%(classname)s"' ' timestamp="%(start_time)s">%(message)s'), ' </testcase>', '</testsuite>', '</testsuites>', @@ -696,8 +696,8 @@ class TextAndXMLTestResultTest(absltest.TestCase): run_time = max(end_time1, end_time2) - min(start_time1, start_time2) timestamp = self._iso_timestamp(start_time1) expected_prefix = """<?xml version="1.0"?> -<testsuites name="" tests="2" failures="0" errors="0" time="%.1f" timestamp="%s"> -<testsuite name="MockTest" tests="2" failures="0" errors="0" time="%.1f" timestamp="%s"> +<testsuites name="" tests="2" failures="0" errors="0" time="%.3f" timestamp="%s"> +<testsuite name="MockTest" tests="2" failures="0" errors="0" time="%.3f" timestamp="%s"> """ % (run_time, timestamp, run_time, timestamp) xml_output = self.xml_stream.getvalue() self.assertTrue( diff --git a/absl/testing/xml_reporter.py b/absl/testing/xml_reporter.py index 5996ce2..591eb7e 100644 --- a/absl/testing/xml_reporter.py +++ b/absl/testing/xml_reporter.py @@ -202,7 +202,7 @@ class _TestCaseResult(object): ('name', '%s' % self.name), ('status', '%s' % status), ('result', '%s' % result), - ('time', '%.1f' % self.run_time), + ('time', '%.3f' % self.run_time), ('classname', self.full_class_name), ('timestamp', _iso8601_timestamp(self.start_time)), ] @@ -263,7 +263,7 @@ class _TestSuiteResult(object): ('tests', '%d' % overall_test_count), ('failures', '%d' % overall_failures), ('errors', '%d' % overall_errors), - ('time', '%.1f' % (self.overall_end_time - self.overall_start_time)), + ('time', '%.3f' % (self.overall_end_time - self.overall_start_time)), ('timestamp', _iso8601_timestamp(self.overall_start_time)), ] _print_xml_element_header('testsuites', overall_attributes, stream) @@ -285,7 +285,7 @@ class _TestSuiteResult(object): ('tests', '%d' % len(suite)), ('failures', '%d' % failures), ('errors', '%d' % errors), - ('time', '%.1f' % (suite_end_time - suite_start_time)), + ('time', '%.3f' % (suite_end_time - suite_start_time)), ('timestamp', _iso8601_timestamp(suite_start_time)), ] _print_xml_element_header('testsuite', suite_attributes, stream) |