I've got a relatively simple SSL server running in Twisted and I'd like to write some unit tests for it. I'm not really sure the best way to do this when using Python 3. All the documentation I've found describes using Twisted Trial which unfortunately is incomplete for Py3k.
What I'm thinking is doing something like this:
- loading up my code and doing everything but
reactor.run()
- send the data I want my code to handle
- run
reactor.doIteration()
(or maybereactor.iterate()
is better?) - check that my server did what it was supposed to
Is this a legitimate way of handling this sort of situation?
EDIT:
answer from glyph that this may be a bad idea (but it's not specifically talking about testing)
EDIT 2:
I guess the major issue is when you're trying to test components intertwined with Twisted and you're not sure how to pull it apart to properly test the individual components. Is there any reliable way to test this? Should .run()
be called and then insert an event that's run a few seconds after you've completed your action to stop the reactor and test the result?