[Twisted-Python] Writing Unittests for Twisted Applications
bh at intevation.de
Tue Jan 7 10:09:34 EST 2003
[Mixin classes for tests that use reactors]
> The test base class is finally publically available inder GPL for now:
Someone asked for a usage example in private mail. There are a few test
cases in the same CVS repository that use the mix-ins, but more
illustrative is probably a very simple example like this:
from reactormixins import ReactorMixin
class Test(unittest.TestCase, ReactorMixin):
"""Extend inherited method to set later_has_been_called to 0"""
self.later_has_been_called = 0
"""Simple test to show how to use ReactorMixin"""
# scheduler self.later to be run after 0.1 seconds
# run the reactor with a 10s time out
"""Record that later has been called and stop the reactor"""
self.later_has_been_called = 1
if __name__ == "__main__":
This example doesn't do any networking but should give an idea of how to
use the mixin classes.
The networking support in the mixins is currently limited to listening
because that all I needed so far. My testcases start sub-processes that
connect to the reactor in the test case.
Intevation GmbH http://intevation.de/
More information about the Twisted-Python