diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ca4c08..714df66a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com). ### Fixed -* The flag `foo` no longer retains the value `bar` after `FLAGS.foo = bar` - fails due to a validation error. +* (flags) The flag `foo` no longer retains the value `bar` after + `FLAGS.foo = bar` fails due to a validation error. +* (testing) Fixed an issue caused by + [this Python 3.12.1 change](https://github.com/python/cpython/pull/109725) + where the test reporter crashes when all tests are skipped. ## 2.0.0 (2023-09-19) diff --git a/absl/testing/xml_reporter.py b/absl/testing/xml_reporter.py index a1143601..4fcb60c8 100644 --- a/absl/testing/xml_reporter.py +++ b/absl/testing/xml_reporter.py @@ -361,6 +361,9 @@ def stopTest(self, test): test_name = test.id() or str(test) sys.stderr.write('No pending test case: %s\n' % test_name) return + if getattr(self, 'start_time', None) is None: + # startTest may not be called for skipped tests since Python 3.12.1. + self.start_time = self.time_getter() test_id = id(test) run_time = self.time_getter() - self.start_time result.set_run_time(run_time) @@ -386,7 +389,7 @@ def stopTestRun(self): # reporting here. for test_id in self.pending_test_case_results: result = self.pending_test_case_results[test_id] - if hasattr(self, 'start_time'): + if getattr(self, 'start_time', None) is not None: run_time = self.suite.overall_end_time - self.start_time result.set_run_time(run_time) result.set_start_time(self.start_time)