Skip to content

Commit 93f0b2e

Browse files
yileicopybara-github
authored andcommitted
Fix absl.testing.xml_reporter for Python 3.12.1 when all tests are skipped.
`startTest` may not be called in this case, after the change in python/cpython#106588. PiperOrigin-RevId: 597675639
1 parent 78af725 commit 93f0b2e

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com).
2626

2727
### Fixed
2828

29-
* The flag `foo` no longer retains the value `bar` after `FLAGS.foo = bar`
30-
fails due to a validation error.
29+
* (flags) The flag `foo` no longer retains the value `bar` after
30+
`FLAGS.foo = bar` fails due to a validation error.
31+
* (testing) Fixed an issue caused by
32+
[this Python 3.12.1 change](https://github.com/python/cpython/pull/109725)
33+
where the test reporter crashes when all tests are skipped.
3134

3235
## 2.0.0 (2023-09-19)
3336

‎absl/testing/xml_reporter.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ def stopTest(self, test):
361361
test_name = test.id() or str(test)
362362
sys.stderr.write('No pending test case: %s\n' % test_name)
363363
return
364+
if getattr(self, 'start_time', None) is None:
365+
# startTest may not be called for skipped tests since Python 3.12.1.
366+
self.start_time = self.time_getter()
364367
test_id = id(test)
365368
run_time = self.time_getter() - self.start_time
366369
result.set_run_time(run_time)
@@ -386,7 +389,7 @@ def stopTestRun(self):
386389
# reporting here.
387390
for test_id in self.pending_test_case_results:
388391
result = self.pending_test_case_results[test_id]
389-
if hasattr(self, 'start_time'):
392+
if getattr(self, 'start_time', None) is not None:
390393
run_time = self.suite.overall_end_time - self.start_time
391394
result.set_run_time(run_time)
392395
result.set_start_time(self.start_time)

0 commit comments

Comments
 (0)