def test_addresses(self):
        """
        A client's transport's C{getHost} and C{getPeer} return L{IPv4Address}
        instances which have the dotted-quad string form of the resolved
        address of the local and remote endpoints of the connection
        respectively as their C{host} attribute, not the hostname originally
        passed in to
        L{connectTCP<twisted.internet.interfaces.IReactorTCP.connectTCP>}, if a
        hostname was used.
        """
        host, ignored = findFreePort(self.interface, self.family)[:2]
        reactor = self.buildReactor()
        fakeDomain = self.fakeDomainName
        reactor.installResolver(FakeResolver({fakeDomain: self.interface}))

        server = reactor.listenTCP(
            0, ServerFactory.forProtocol(Protocol), interface=host)
        serverAddress = server.getHost()

        transportData = {'host': None, 'peer': None, 'instance': None}

        class CheckAddress(Protocol):
            def makeConnection(self, transport):
                transportData['host'] = transport.getHost()
                transportData['peer'] = transport.getPeer()
                transportData['instance'] = transport
                reactor.stop()

        clientFactory = Stop(reactor)
        clientFactory.protocol = CheckAddress

        def connectMe():
            while True:
                port = findFreePort(self.interface, self.family)
                bindAddress = (self.interface, port[1])
                log.msg("Connect attempt with bindAddress {}".format(
                    bindAddress
                ))
                try:
                    reactor.connectTCP(
                        fakeDomain,
                        server.getHost().port,
                        clientFactory,
                        bindAddress=bindAddress,
                    )
                except ConnectBindError:
                    continue
                else:
                    clientFactory.boundPort = port[1]
                    break

        needsRunningReactor(reactor, connectMe)

        self.runReactor(reactor)

        if clientFactory.failReason:
            self.fail(clientFactory.failReason.getTraceback())

        transportRepr = "<%s to %s at %x>" % (
            transportData['instance'].__class__,
            transportData['instance'].addr,
            id(transportData['instance']))

        boundPort = [host] + list(socket.getaddrinfo(
            self.interface, clientFactory.boundPort)[0][-1][1:])
        serverPort = [host] + list(socket.getaddrinfo(
            self.interface, serverAddress.port)[0][-1][1:])

        self.assertEqual(
            transportData['host'],
            self.addressClass('TCP', *boundPort))
        self.assertEqual(
            transportData['peer'],
            self.addressClass('TCP', *serverPort))
        self.assertEqual(
            repr(transportData['instance']), transportRepr)

        A client's transport's C{getHost} and C{getPeer} return L{IPv4Address}
        instances which have the dotted-quad string form of the resolved
        address of the local and remote endpoints of the connection
        respectively as their C{host} attribute, not the hostname originally
        passed in to
        L{connectTCP<twisted.internet.interfaces.IReactorTCP.connectTCP>}, if a
        hostname was used.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/test/test_tcp.py