[Pyunit-interest] Running tests in parallel
Brought to you by:
purcell
From: Steve P. <ste...@ya...> - 2001-02-16 07:35:03
|
Bill Bumgarner wrote: > Finally, I want to be able to run multiple test suites simultaneously > within a single Python VM. In particular, it is often the case that the > only effective way to test an application for, say, threading issues or > other multiuser related issues is to run the app through its paces from > multiple clients simultaneously. The following vaguely hacky code might help: class ParallelTestSuite(unittest.TestSuite): """Runs its tests in parallel threads""" def __call__(self, testResult): from threading import Thread threads = [] for test in self._tests: result = test.defaultTestResult() thread = Thread(target=test, args=(result,)) threads.append((test, thread, result)) thread.start() for test, thread, result in threads: thread.join() testResult.startTest(test) for error in result.errors: apply(testResult.addError, error) for failure in result.failures: apply(testResult.addFailure, failure) testResult.stopTest(test) (Most test result classes aren't thread safe, hence the complication of the above) -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ Get servlets at http://pyserv.sourceforge.net/ "Even snakes are afraid of snakes." -- Steven Wright |