I See Dead Code

… as sounding brass, or a tinkling cymbal.

I See Dead Code header image 4

Random Python unittesting snippet #1

Dezember 18th, 2007 · No Comments

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): [...]

[Read more →]

Tags: lang:en · programming · python