def test_flushesOnExitWithException(self):
        """
        The context manager flushes its buffered logs when the block
        terminates because of an exception.
        """
        class TestException(Exception):
            """
            An exception only raised by this test.
            """

        with self.assertRaises(TestException):
            with self.logBuffer as logger:
                logger.info("An event")
                self.assertFalse(self.events)
                raise TestException()

        self.assertEqual(1, len(self.events))
        [event] = self.events
        self.assertEqual(event['log_format'], "An event")
        self.assertEqual(event['log_namespace'], self.namespace)

        The context manager flushes its buffered logs when the block
        terminates because of an exception.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/test/test_tcp.py