Skip to content

Record the class termination signal in TestClassInfoRecord - #1071

Merged
xpconanfan merged 8 commits into
masterfrom
class_level_record
Oct 17, 2026
Merged

xpconanfan merged 8 commits into
masterfrom
class_level_record

Conversation

@xpconanfan

@xpconanfan xpconanfan commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Records the signal that terminated a test class in TestClassInfoRecord (Type: TestClassInfo):

  1. mobly/records.py: class_end(e=None) stores the terminating exception or TestSignal as an ExceptionRecord, and to_dict adds Details, Termination Signal Type, Stacktrace and Extras next to the existing timestamps. Nothing is derived from the test records; counts and pass/fail state stay in TestResult.

  2. mobly/base_test.py: run() passes the TestAbortClass/TestAbortAll signal, or whatever exception escapes the class body or teardown_class, to class_end. _pre_run() now resets and checks expects.recorder like _setup_class() does, so expects.expect_* failures in pre_run are recorded as class errors instead of being lost.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances test execution tracking and reporting in Mobly by expanding TestClassInfoRecord to capture detailed class-level test results, counts, and termination signals. It also refactors the test class and suite runner lifecycles to ensure proper cleanup and accurate reporting under various failure scenarios, supported by comprehensive unit tests. The review feedback highlights two key improvements: preventing the suppression of primary termination errors by cleanup exceptions in base_test.py, and ensuring PEP 8 compliance in records.py by explicitly returning None in property getters.

Comment thread mobly/base_test.py
Comment thread mobly/records.py Outdated
Comment thread mobly/base_test.py Outdated
Comment thread mobly/base_test.py Outdated
Comment thread mobly/records.py Outdated
* TestClassInfoRecord no longer carries Requested/Executed/Passed/Failed/
  Skipped/Error counts; it keeps Result and the termination signal.
* run() keeps _pre_run, test-name resolution and _get_test_methods outside
  the try block as before, so no setup_class_reached flag is needed and
  _teardown_class() is always the finalizer.
* Remove the summary_writer None-guards; summary_writer is always set by
  TestRunner, consistent with the other dump call sites.
@xpconanfan xpconanfan changed the title Enrich TestClassInfoRecord with per-class counts, result, and termination signal Enrich TestClassInfoRecord with class result and termination signal Oct 15, 2026
* class_end(results, e=None): derive the termination signal from e or the
  first class-stage error record, and the result from results.is_all_pass
  in one short decision chain; drop the four pass-through properties and
  build to_dict as a literal.
* Replace _get_eventually_passing_retry_record_ids with
  _eventually_passing_retries returning the records themselves.
* In run(), whatever escapes _teardown_class is recorded as the terminator,
  with no precedence special-casing.
@xpconanfan

Copy link
Copy Markdown
Collaborator Author

Pushed a simplification pass: class_end(results, e=None) now derives the signal (from e, else the first class-stage error record) and the result (is_all_pass → ERROR/FAIL, else PASS/SKIP) in one short chain; the pass-through properties are gone and to_dict is a literal. In run(), whatever escapes _teardown_class is simply recorded as the terminator, no precedence special-casing. Net diff vs master is now +50/−20 in base_test.py and +60/−10 in records.py.

Comment thread mobly/base_test.py Outdated
@xpconanfan xpconanfan added the kokoro:force-run Trigger kokoro run after errors. label Oct 15, 2026
@kokoro-team kokoro-team removed the kokoro:force-run Trigger kokoro run after errors. label Oct 15, 2026
Comment thread mobly/records.py Outdated
Comment thread mobly/records.py Outdated
Comment thread mobly/records.py Outdated
* Result is derived from TestResult alone: not all-pass -> ERROR if any
  error record else FAIL; otherwise PASS unless only skips -> SKIP. No
  signal-type inspection.
* to_dict uses TestResultEnums directly instead of 1:1 KEY_ aliases.
* _count_eventually_passing_retries is back to its original form.
* TestSkip in setup_class is out of scope for this PR; removed with its test.
Comment thread mobly/suite_runner.py Outdated
Comment thread mobly/records.py Outdated
Comment thread mobly/records.py Outdated
The result of a class is already fully described by its test records and
TestResult; computing it again at the class level duplicated that logic.
class_end(e=None) now only stores the terminating signal.
@xpconanfan xpconanfan changed the title Enrich TestClassInfoRecord with class result and termination signal Record the class termination signal in TestClassInfoRecord Oct 15, 2026
@xpconanfan xpconanfan self-assigned this Oct 15, 2026
@xpconanfan xpconanfan added this to the Mobly Release 1.14 milestone Oct 15, 2026
@xpconanfan
xpconanfan merged commit 096cfd6 into master Oct 17, 2026
19 checks passed
@xpconanfan
xpconanfan deleted the class_level_record branch October 17, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants