Skip to content

Commit

Permalink
Pything testing: Add more info to error summary (#36216)
Browse files Browse the repository at this point in the history
Get correct line for assert.fail too
  • Loading branch information
cecille authored Oct 23, 2024
1 parent 614a086 commit c28bcdc
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@ class TestStep:
expectation: str = ""
is_commissioning: bool = False

def __str__(self):
return f'{self.test_plan_number}: {self.description}\tExpected outcome: {self.expectation}'


@dataclass
class TestInfo:
Expand Down Expand Up @@ -1325,7 +1328,7 @@ def extract_error_text() -> tuple[str, str]:
if not trace:
return no_stack_trace

if isinstance(exception, signals.TestError):
if isinstance(exception, signals.TestError) or isinstance(exception, signals.TestFailure):
# Exception gets raised by the mobly framework, so the proximal error is one line back in the stack trace
assert_candidates = [idx for idx, line in enumerate(trace) if "asserts" in line and "asserts.py" not in line]
if not assert_candidates:
Expand All @@ -1343,6 +1346,9 @@ def extract_error_text() -> tuple[str, str]:
return probable_error.strip(), trace[file_candidates[-1]].strip()

probable_error, probable_file = extract_error_text()
test_steps = self.get_defined_test_steps(self.current_test_info.name)
test_step = str(test_steps[self.current_step_index-1]
) if test_steps is not None else 'UNKNOWN - no test steps provided in test script'
logging.error(textwrap.dedent(f"""
******************************************************************
Expand All @@ -1353,8 +1359,12 @@ def extract_error_text() -> tuple[str, str]:
* {probable_file}
* {probable_error}
*
* Test step:
* {test_step}
*
* Endpoint: {self.matter_test_config.endpoint}
*
*******************************************************************
"""))

def on_pass(self, record):
Expand Down

0 comments on commit c28bcdc

Please sign in to comment.