def _execute_nodes( self, exec_ctx: ctx.ExecutionContext, result: res.ExecutionResult, ): for idx, node in enumerate(exec_ctx.executable_nodes()): try: if self._logger.isEnabledFor(logging.DEBUG): self._logger.debug("Executing %s", astor.to_source(node)) code = compile(node, "<ast>", "exec") # pylint: disable=exec-used exec(code, exec_ctx.global_namespace, exec_ctx.local_namespace) # nosec except Exception as err: # pylint: disable=broad-except failed_stmt = astor.to_source(node) TestCaseExecutor._logger.debug( "Failed to execute statement:\n%s%s", failed_stmt, err.args ) result.report_new_thrown_exception(idx, err) break
def test_exceptions(): result = ExecutionResult() ex = Exception() result.report_new_thrown_exception(0, ex) assert result.exceptions[0] == ex
def test_get_first_position_of_ex(): result = ExecutionResult() result.report_new_thrown_exception(5, Exception()) result.report_new_thrown_exception(3, Exception()) assert result.get_first_position_of_thrown_exception() == 3
def test_report_new_thrown_exception(): result = ExecutionResult() result.report_new_thrown_exception(0, Exception()) assert result.has_test_exceptions()