unittest.assertRaise and keyword arguments?
Giovanni Bajo
raNOsky at deveSPAMler.com
Fri Dec 2 14:55:58 EST 2005
Bo Peng wrote:
> The syntax for using assertRaise is
>
> assertRaise(exception, function, para1, para2,...)
>
> However, I have a long list of arguments (>20) so I would like to test
> some of them using keyword arguments (use default for others). Is there
> a way to do this except for manually try...except?
You can pass keyword arguments to assertRaises without problems:
self.assertRaises(ValueError, myfunc, arg1,arg2, arg3, arg4, abc=0, foo=1,
bar="hello")
Or you can always do something like:
self.assertRaises(ValueError, lambda: myfunc(arg1,arg2, arg3, arg4, abc=0,
foo=1, bar="hello"))
--
Giovanni Bajo
More information about the Python-list
mailing list