Skip to content

Commit

Permalink
Fix absl.testing.xml_reporter for Python 3.12.1 when all tests are sk…
Browse files Browse the repository at this point in the history
…ipped.

`startTest` may not be called in this case, after the change in python/cpython#106588.

PiperOrigin-RevId: 597675639
  • Loading branch information
yilei authored and copybara-github committed Jan 12, 2024
1 parent 78af725 commit 93f0b2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion absl/testing/xml_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 93f0b2e

Please sign in to comment.