Package flumotion :: Package twisted :: Module integration
[hide private]

Module integration

source code

Framework for writing automated integration tests.

This module provides a way of writing automated integration tests from within Twisted's unit testing framework, trial. Test cases are constructed as subclasses of the normal trial twisted.trial.unittest.TestCase class.

Integration tests look like normal test methods, except that they are decorated with integration.test, take an extra "plan" argument, and do not return anything. For example:

 from twisted.trial import unittest
 from flumotion.twisted import integration

 class IntegrationTestExample(unittest.TestCase):
     @integration.test
     def testEchoFunctionality(self, plan):
         process = plan.spawn('echo', 'hello world')
         plan.wait(process, 0)

This example will spawn a process, as if you typed "echo 'hello world'" at the shell prompt. It then waits for the process to exit, expecting the exit status to be 0.

The example illustrates two of the fundamental plan operators, spawn and wait. "spawn" spawns a process. "wait" waits for a process to finish. The other operators are "spawnPar", which spawns a number of processes in parallel, "waitPar", which waits for a number of processes in parallel, and "kill", which kills one or more processes via SIGTERM and then waits for them to exit.

It is evident that this framework is most appropriate for testing the integration of multiple processes, and is not suitable for in-process tests. The plan that is built up is only executed after the test method exits, via the integration.test decorator; the writer of the integration test does not have access to the plan's state.

Note that all process exits must be anticipated. If at any point the integration tester receives SIGCHLD, the next operation must be a wait for that process. If this is not the case, the test is interpreted as having failed.

Also note that while the test is running, the stdout and stderr of each spawned process is redirected into log files in a subdirectory of where the test is located. For example, in the previous example, the following files will be created:

 $testdir/IntegrationTestExample-$date/testEchoFunctionality/echo.stdout
 $testdir/IntegrationTestExample-$date/testEchoFunctionality/echo.stderr

In the case that multiple echo commands are run in the same plan, the subsequent commands will be named as echo-1, echo-2, and the like. Upon successful completion of the test case, the log directory will be deleted.


Version: $Rev: 6561 $

Classes [hide private]
  UnexpectedExitCodeException
  UnexpectedExitException
  CommandNotFoundException
  ProcessesStillRunningException
  TimeoutException
  ProcessProtocol
  Process
  PlanExecutor
  Plan
Functions [hide private]
 
log(format, *args) source code
 
debug(format, *args) source code
 
info(format, *args) source code
 
warning(format, *args) source code
 
error(format, *args) source code
 
_which(executable) source code
 
test(proc) source code