[Pyunit-interest] passing arguments to TestCase constructor through makeSuite
Brought to you by:
purcell
From: Andrew W. <ci...@gw...> - 2000-09-15 20:47:08
|
In my application, I'm passing some contextual information into my TestCase constructor with a couple of extra arguments. (I'm using Zope, and the request information is passed in to me as an argument). This is easy enough to do, but the makeSuite function only calls the constructor with the method name. Here is my extension to makeSuite() that I'm using to allow me to pass through my necessary extra arguments. def makeSuite(testCaseClass, prefix='test', sortUsing=cmp, arguments=()): """Returns a TestSuite instance built from all of the test functions in the given test case class whose names begin with the given prefix. The cases are sorted by their function names using the supplied comparison function, which defaults to 'cmp'. The test case class constructor is called with the method name, and any extra arguments passed in 'arguments'. """ cases = map(lambda methodName, testCaseClass=testCaseClass, arguments=arguments: apply(testCaseClass, (methodName,) + arguments), getTestCaseNames(testCaseClass, prefix, sortUsing)) return TestSuite(cases) |