Setup, execute and teardown a test case in this suite. Exceptions are caught and recorded in logs and results.
(
self, test_case_method: MethodType, test_case_result: TestCaseResult
)
| 364 | return match |
| 365 | |
| 366 | def _run_test_case( |
| 367 | self, test_case_method: MethodType, test_case_result: TestCaseResult |
| 368 | ) -> None: |
| 369 | """ |
| 370 | Setup, execute and teardown a test case in this suite. |
| 371 | Exceptions are caught and recorded in logs and results. |
| 372 | """ |
| 373 | test_case_name = test_case_method.__name__ |
| 374 | |
| 375 | try: |
| 376 | # run set_up function for each case |
| 377 | self.set_up_test_case() |
| 378 | test_case_result.update_setup(Result.PASS) |
| 379 | except SSHTimeoutError as e: |
| 380 | self._logger.exception(f"Test case setup FAILED: {test_case_name}") |
| 381 | test_case_result.update_setup(Result.FAIL, e) |
| 382 | except Exception as e: |
| 383 | self._logger.exception(f"Test case setup ERROR: {test_case_name}") |
| 384 | test_case_result.update_setup(Result.ERROR, e) |
| 385 | |
| 386 | else: |
| 387 | # run test case if setup was successful |
| 388 | self._execute_test_case(test_case_method, test_case_result) |
| 389 | |
| 390 | finally: |
| 391 | try: |
| 392 | self.tear_down_test_case() |
| 393 | test_case_result.update_teardown(Result.PASS) |
| 394 | except Exception as e: |
| 395 | self._logger.exception(f"Test case teardown ERROR: {test_case_name}") |
| 396 | self._logger.warning( |
| 397 | f"Test case '{test_case_name}' teardown failed, " |
| 398 | f"the next test case may be affected." |
| 399 | ) |
| 400 | test_case_result.update_teardown(Result.ERROR, e) |
| 401 | test_case_result.update(Result.ERROR) |
| 402 | |
| 403 | def _execute_test_case( |
| 404 | self, test_case_method: MethodType, test_case_result: TestCaseResult |
no test coverage detected