aboutsummaryrefslogtreecommitdiff
path: root/absl/testing/tests
diff options
context:
space:
mode:
authorCraig Citro <craigcitro@google.com>2020-01-31 15:01:22 -0800
committerCopybara-Service <copybara-worker@google.com>2020-01-31 15:01:44 -0800
commite8fb252483bf2ff82021104298b6fd0b80d2f0f0 (patch)
tree831f4d51a8fb753c97fb44b78b47b3253baf071a /absl/testing/tests
parentdb5bf716d892c3a3e7b9929a5b63bcdb1a3177ea (diff)
downloadabsl-py-e8fb252483bf2ff82021104298b6fd0b80d2f0f0.tar.gz
Record the seed used for test order randomization in test.xml.
Currently, if a user requests randomization of test case execution order, the only place this is recorded is in a logging statement during test execution. If a user is both (1) randomizing test case execution order and (2) using the xml_reporter to produce a test summary, this CL adds a new property to the top-level testsuites entry including the seed used for randomizing the order of test cases. Along the way, I made two incidental changes: * I renamed the testLoader's `_seed` attribute to `_randomization_order_seed` for clarity, as there were at least two seeds already floating around in this file (the other being related to `--test_random_seed`). * I cleaned up some dead code in the test, and commandeered an otherwise-dead method (`_run_test_and_get_xml`) for use in a test of the new XML logging. PiperOrigin-RevId: 292623509 Change-Id: I53da355d4a1c5a11b5e6e8622745fa466840e0ce
Diffstat (limited to 'absl/testing/tests')
-rwxr-xr-xabsl/testing/tests/xml_reporter_test.py41
1 files changed, 15 insertions, 26 deletions
diff --git a/absl/testing/tests/xml_reporter_test.py b/absl/testing/tests/xml_reporter_test.py
index 783b218..f4a6c2d 100755
--- a/absl/testing/tests/xml_reporter_test.py
+++ b/absl/testing/tests/xml_reporter_test.py
@@ -951,7 +951,7 @@ class XmlReporterFixtureTest(absltest.TestCase):
binary = self._get_helper()
args = [binary, flag, '--xml_output_file=%s' % xml_fname]
ret = subprocess.call(args)
- self.assertNotEqual(ret, 0)
+ self.assertEqual(ret, 0)
xml = ElementTree.parse(xml_fname).getroot()
finally:
@@ -1001,31 +1001,6 @@ class XmlReporterFixtureTest(absltest.TestCase):
return xml
- def _test_for_error(self, flag, message):
- """Run the test and look for an Error with the specified message."""
- ret, xml = self._run_test_with_subprocess(flag)
- self.assertNotEqual(ret, 0)
- self.assertEqual(int(xml.attrib['errors']), 1)
- self.assertEqual(int(xml.attrib['failures']), 0)
- for msg in xml.iter('error'):
- if msg.attrib['message'] == message:
- break
- else:
- self.fail(msg='Did not find message: "%s" in xml\n%s' % (
- message, ElementTree.tostring(xml)))
-
- def _test_for_failure(self, flag, message):
- """Run the test and look for a Failure with the specified message."""
- ret, xml = self._run_test_with_subprocess(flag)
- self.assertNotEqual(ret, 0)
- self.assertEqual(int(xml.attrib['errors']), 0)
- self.assertEqual(int(xml.attrib['failures']), 1)
- for msg in xml.iter('failure'):
- if msg.attrib['message'] == message:
- break
- else:
- self.fail(msg='Did not find message: "%s"' % message)
-
def test_set_up_module_error(self):
self._run_test(
flag='--set_up_module_error',
@@ -1157,6 +1132,20 @@ class XmlReporterFixtureTest(absltest.TestCase):
'classname': '__main__.FailableTest',
'failure': 'test Failed!'}]}])
+ def test_test_randomization_seed_logging(self):
+ # We expect the resulting XML to start as follows:
+ # <testsuites ...>
+ # <properties>
+ # <property name="test_randomize_ordering_seed" value="17" />
+ # ...
+ #
+ # which we validate here.
+ out = self._run_test_and_get_xml('--test_randomize_ordering_seed=17')
+ expected_attrib = {'name': 'test_randomize_ordering_seed', 'value': '17'}
+ property_attributes = [
+ prop.attrib for prop in out.findall('./properties/property')]
+ self.assertIn(expected_attrib, property_attributes)
+
if __name__ == '__main__':
absltest.main()