A small context manager for stating assertions about exceptions in Python unit tests: @contextmanager def assert_raises(*exc_types): """A context to ensure that an exception of a given type is thrown. Instead of @nose.tools.raises(ValueError) def test_that_raises(): # … lengthy setup raise ValueError you can write def test_that_raises_at_the_end(): # … lengthy setup with assert_raises(ValueError): [...]
Random Python unittesting snippet #1
Dezember 18th, 2007 · No Comments
Tags: lang:en · programming · python

![Validate my RSS feed [Valid RSS]](http://shlomme.diotavelli.net/images/valid-rss.png)