def test_traceback_size_limit(self): """Insert a failure with a long exception and make sure it gets truncated.""" conn = self.reporter.conn test_case = DummyTestCase() result = TestResult(test_case.test_fail) result.start() result.end_in_failure( (type(AssertionError), AssertionError('A' * 200), None)) with patch.object(self.reporter.options, 'sql_traceback_size', 50): with patch.object( result, 'format_exception_info') as mock_format_exception_info: mock_format_exception_info.return_value = "AssertionError: %s\n%s\n" % ( 'A' * 200, 'A' * 200) self.reporter.test_complete(result.to_dict()) assert self.reporter.report() failure = conn.execute(self.reporter.Failures.select()).fetchone() assert_equal(len(failure.traceback), 50) assert_equal(len(failure.error), 50) assert_in('Exception truncated.', failure.traceback) assert_in('Exception truncated.', failure.error)
def run_fixture(self, fixture, function_to_call, enter_callback=None, exit_callback=None): result = TestResult(fixture) try: result.start() if enter_callback: enter_callback(result) if result.record(function_to_call): result.end_in_success() else: return result.exception_infos finally: if exit_callback: exit_callback(result)
def run_fixture(self, fixture, function_to_call, enter_callback=None, exit_callback=None): result = TestResult(fixture) try: result.start() if enter_callback: enter_callback(result) if result.record(function_to_call): result.end_in_success() else: return result.exception_infos except (KeyboardInterrupt, SystemExit): result.end_in_interruption(sys.exc_info()) raise finally: if exit_callback: exit_callback(result)
def run_fixture(self, fixture, function_to_call, enter_callback=None, exit_callback=None): result = TestResult(fixture) try: result.start() if enter_callback: enter_callback(result) if result.record(function_to_call): result.end_in_success() else: return result.exception_infos except (KeyboardInterrupt, SystemExit): result.end_in_interruption(sys.exc_info()) raise finally: if exit_callback: exit_callback(result)
def test_json_reporter_reports(self): self.set_options() with mock_conf_files(): self.reporter = TestCaseJSONReporter(self.options) test_case = TestCase() fake_test_result = TestResult(test_case.run) with mock.patch.object(datetime, 'datetime', **{'now.return_value': start_time}): fake_test_result.start() with mock.patch.object(datetime, 'datetime', **{'now.return_value': end_time}): fake_test_result._complete() self.reporter.test_case_complete(fake_test_result.to_dict()) assert_equal( json.loads(self.reporter.log_file.getvalue()), json.loads(output_str), )
def test_json_reporter_reports(self): self.set_options() with mock_conf_files(): self.reporter = TestCaseJSONReporter(self.options) test_case = TestCase() fake_test_result = TestResult(test_case.run) with mock.patch.object( datetime, 'datetime', **{'now.return_value': start_time} ): fake_test_result.start() with mock.patch.object(datetime, 'datetime', **{'now.return_value': end_time}): fake_test_result._complete() self.reporter.test_case_complete(fake_test_result.to_dict()) assert_equal( json.loads(self.reporter.log_file.getvalue()), json.loads(output_str), )
def run_fixture(self, fixture, function_to_call, enter_callback=None, exit_callback=None): result = TestResult(fixture) try: result.start() if enter_callback: enter_callback(result) if result.record(function_to_call): result.end_in_success() else: return result.exception_infos finally: if exit_callback: exit_callback(result)
def test_frame_stripping(self, mock_format_exception): """On assertion error, testify strips head and tail frame which originate from testify.""" test_result = TestResult(lambda:'wat', runner_id='foo!') test_result.start() root_tb = tb = mock.Mock() testify_frames = [True, True, False, True, False, True, True] for testify_frame in testify_frames: tb.tb_next = mock.Mock() tb = tb.tb_next tb.configure_mock(**{'tb_frame.f_globals.has_key.return_value': testify_frame}) tb.tb_next = None tb = root_tb.tb_next test_result.end_in_failure((AssertionError, 'wat', tb)) formatted = test_result.format_exception_info() assert_equal(formatted, 'Traceback: AssertionError\n') # It should format three frames of the stack, starting with the third frame. mock_format_exception.assert_called_with(AssertionError, 'wat', tb.tb_next.tb_next, 3)
def test_traceback_size_limit(self): """Insert a failure with a long exception and make sure it gets truncated.""" conn = self.reporter.conn test_case = DummyTestCase() result = TestResult(test_case.test_fail) result.start() result.end_in_failure((type(AssertionError), AssertionError('A' * 200), None)) with patch.object(self.reporter.options, 'sql_traceback_size', 50): with patch.object(result, 'format_exception_info') as mock_format_exception_info: mock_format_exception_info.return_value = ["AssertionError: %s" % ('A' * 200), 'A' * 200] self.reporter.test_complete(result.to_dict()) assert self.reporter.report() failure = conn.execute(Failures.select()).fetchone() assert_equal(len(failure.traceback), 50) assert_equal(len(failure.error), 50) assert_in('Exception truncated.', failure.traceback) assert_in('Exception truncated.', failure.error)