Attest provides some context managers that are useful for writing tests.
Fails if none of the exceptions are raised inside the context. This reverses failure semantics and is useful for testing code that uses exceptions as part of its API.
>>> with raises(IOError) as error: ... open('/etc/passwd', 'w') ... >>> error.errno 13
|Parameters:||exceptions – Expected exception classes.|
|Returns:||An Error on which the caught exception is set after the context has executed, if one was raised.|
|If none of the expected exceptions are raised in the context.|
New in version 0.5.
Captures standard output and error during the context. Returns a tuple of the two streams as lists of lines, added after the context has executed.
>>> with capture_output() as (out, err): ... print 'Captured' ... >>> out ['Captured']
Blocks the given names from being imported inside the context. This is useful for testing import-dependent fallbacks.
>>> with disable_imports('sys'): ... import sys ... Traceback (most recent call last): ImportError: 'sys' is disabled
New in version 0.4.