nose-devs/nose — pull request #533 by tonyseek (2012-07-26 05:21:36+00:00)
Title: Made tools.raises support 'with statement' and exception checker.

I think that the `nose.tools.raises` is a excellent design, with it we could assert the exception with a simple function. However, the decorator could not be used alike a with statement, we may have to write a standalone function to check a exception even the checking is a part of a test case. Otherwise, sometime we may want to check the attribute or other feature of a exception instance, the decorator could not do that.

By those reason, I has extended the `raises` decorator. In the tools module of this pull request, the `raises` could be used as a decorator just like before, and it could be used as a with statment too. If we want to check the raised exception, we could add a keyword argument named `checker`.

```python
def check_value_error(e):
assert e.message == "ouch!"

def test_it():
with raises(ValueError, checker=check_value_error, name="test_foo"):
raise ValueError("ouch!")

with raises(TypeError):
raise TypeError("ouch!")

@raises(ValueError)
def test_foo():
raise ValueError
```

My modified is backward compatibility with current released version. If anyone have opinions about this modified, please comment to me. Thanks.