def temp_directory(*args, **kwargs):
    """
    Context manager returns a path created by mkdtemp and cleans it up afterwards.
    """

    path = tempfile.mkdtemp(*args, **kwargs)
    try:
        yield path
    finally:
        shutil.rmtree(path)
Context manager returns a path created by mkdtemp and cleans it up afterwards.