I’m using nose 1.1.2 to write tests for a Python project. There is this assert_raises function that happens to be mentioned in the documentation but I can’t find it anywhere.
It should be a shorthand for something like this:
value_error_raised = False
try:
do_something_that_should_raise_value_error()
except ValueError:
value_error_raised = True
assert value_error_raised
type_error_raised = False
try:
do_something_else_that_should_raise_type_error()
except TypeError:
type_error_raised = True
assert type_error_raised
that would become:
assert_raises(ValueError,
do_something_that_should_raise_value_error)
assert_raises(TypeError,
do_something_else_that_should_raise_type_error)
I already searched the source code and the only mention I found was in the tools.py module, inside the raises documentation:
If you want to test many assertions about exceptions in a single test, you may want to use
assert_raisesinstead.
Was this function removed from nose? If so, could someone help me understand why?
I personally use the unittest2.TestCase classes with nosetests, and use self.assertRaises.