예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)