[Twisted-Python] Conch Testing server and client

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Jul 1 06:42:55 MDT 2011

On 12:14 pm, anshul.singhle at gmail.com wrote:
>I have to write tests for a custom conch server. My approach is to make 
>test client and then connect it to my server in my testcase. I have 
>able to create a client that can interface with my server, but i'm not 
>to do it from within the test case.
>What I'm trying is :
>class TestAccountStatus(unittest.TestCase):
>     def setUp(self):
>         ssh_server = Server()
>         self.server = reactor.listenTCP(ssh_server.port,
>                      ssh_server.application(),
>                      interface=ssh_server.interface)
>     def tearDown(self):
>         server, self.server = self.server,None
>         return server.stopListening()
>     def test_1(self):
>         d = protocol.ClientCreator(reactor,
>SimpleTransport).connectTCP('localhost', self.server.getHost().port)
>         return d
>The transport SimpleTransport is my custom transport.SSHClientTransport
>instance. The class Server() is a wrapper around an SSHFactory 
>The problem I'm facing is that after this line >
>d = protocol.ClientCreator(reactor, 
>I have to write reactor.run(), otherwise the client is not starting. If 
>write reactor.run() the test doesn't stop (understandable since the 
>isn't being stopped).
>Basically I want to know how I can start the client without running

The reactor should be started for you, automatically.


More information about the Twisted-Python mailing list