def tmp_file(*args, **kwargs):
    """
    Context manager that generates a temporary file, yields the file descriptor number and temporary
    path, and eventually removes the files. All *args* and *kwargs* are passed to
    :py:meth:`tempfile.mkstemp`.
    """
    fileno, path = tempfile.mkstemp(*args, **kwargs)

    # create the file
    with open(path, "w") as f:
        f.write("")

    # yield it
    try:
        yield fileno, path
    finally:
        if os.path.exists(path):
            os.remove(path)