Discussion:
unittest.assertRaise and keyword arguments?
Bo Peng
2005-12-02 20:11:04 UTC
Permalink
self.assertRaises(ValueError, myfunc, arg1,arg2, arg3, arg4, abc=0, foo=1,
bar="hello")
Well, I though abc=0 would be keyword arguments for assertRaisers and
never tried it!
self.assertRaises(ValueError, lambda: myfunc(arg1,arg2, arg3, arg4, abc=0,
foo=1, bar="hello"))
This is also useful.

I now have nothing to complain against assertTaises. :-)

Bo
Giovanni Bajo
2005-12-02 19:55:58 UTC
Permalink
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
Bo Peng
2005-12-02 19:34:08 UTC
Permalink
Dear list,

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?

Thanks.
Bo

Loading...