def test_deadReferenceError(self):
        """
        Test that when a connection is lost, calling a method on a
        RemoteReference obtained from it raises L{DeadReferenceError}.
        """
        self.establishClientAndServer()
        rootObjDeferred = self.clientFactory.getRootObject()

        def gotRootObject(rootObj):
            disconnectedDeferred = Deferred()
            rootObj.notifyOnDisconnect(disconnectedDeferred.callback)

            def lostConnection(ign):
                self.assertRaises(
                    pb.DeadReferenceError,
                    rootObj.callRemote, 'method')

            disconnectedDeferred.addCallback(lostConnection)
            self.clientFactory.disconnect()

            self.completeClientLostConnection()

            return disconnectedDeferred

        return rootObjDeferred.addCallback(gotRootObject)

        Test that when a connection is lost, calling a method on a
        RemoteReference obtained from it raises L{DeadReferenceError}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/spread/test/test_pb.py