def test_prepareConnectionThrows(self):
        """
        The connection attempt counts as a failure when the
        C{prepareConnection} callable throws.
        """
        clock = Clock()

        def prepareConnection(_proto):
            raise IndentationError()

        cq, service = self.makeReconnector(prepareConnection=prepareConnection,
                                           clock=clock)

        whenConnectedDeferred = service.whenConnected(failAfterFailures=2)
        self.assertNoResult(whenConnectedDeferred)

        clock.advance(AT_LEAST_ONE_ATTEMPT)
        self.assertNoResult(whenConnectedDeferred)

        clock.advance(AT_LEAST_ONE_ATTEMPT)
        self.assertIdentical(IndentationError,
                             self.failureResultOf(whenConnectedDeferred).type)

        The connection attempt counts as a failure when the
        C{prepareConnection} callable throws.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/application/test/test_internet.py