@contextlib.contextmanager<EOL>def tempdir():
dirpath = tempfile.mkdtemp()<EOL>try:<EOL><INDENT>with in_directory(dirpath):<EOL><INDENT>yield dirpath<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>shutil.rmtree(dirpath)<EOL><DEDENT>
Context manager that moves in a temporary directory.

.. code::

    # We are in the initial working directory
    with tempdir():
        # We are now in a temporary directory
        ...
    # We are back to the initial working directory.
    # The temporary does not exist anymore.