Python assertRaises on user-defined exceptions
问题 The following question was triggered by the discussion in this post. Assume two files ( foobar.py and foobar_unittest.py ). File foobar.py contains a class ( FooBar ) with two functions ( foo and bar ). Function bar raises a built-in exception, function foo a user-defined exception. # foobar.py class MyException(Exception): pass class FooBar: def __init__(self): pass def bar(self): raise ValueError('Hello World.') def foo(self): raise MyException('Hello World.') . # foobar_unittest.py import