Where is the nose function assert_raises?

I use nose 1.1.2 to write tests for a Python project. There is a function assert_raisesthat is mentioned in the documentation, but I cannot find it.

This 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

which will be as follows:

assert_raises(ValueError,
              do_something_that_should_raise_value_error)

assert_raises(TypeError,
              do_something_else_that_should_raise_type_error)

I was already looking for the source code, and the only mention I found was in the tools.py module inside the documentation raises:

If you want to test many exception statements in one test, you can use instead assert_raises.

Has this feature been removed from the nose? If so, can someone help me understand why?

+5
source share
3 answers
>>> from nose.tools import assert_raises
>>> assert_raises
<bound method Dummy.assertRaises of <nose.tools.Dummy testMethod=nop>>
>>> import nose
>>> nose.__version__
'1.1.2'

I personally use unittest2.TestCase classes with nosetests and use self.assertRaises.

+7
+5

This answer refers to the reason you cannot find information about assert_raises.

From the nose documentation :

The nose.tools module provides [...] all the same assertX methods as in unittest.TestCase (only for PEP 8, therefore assert_equal, not assertEqual)

So PEP 8 suggested a naming function and an assertX Method List in the Python core documentation.

+1
source