Skip to content

contextlib

jasper-zanjani edited this page Aug 6, 2020 · 1 revision

Build a context manager out of generator functions - function it decorates must run exactly twice (typically try ... yield finally ... structure) - yield can pass a value back (can be assigned to variable after as keyword)\

@contextmanager

capsys fixture - from pytest allows access to stdout/stderr output generated during text execution contextlib.redirect_stdout - context manager temporarily redirects sys.stdout to another file or file-like object