import pathlib


def invalid_file(tmpdir, request):
    """Return a path to an invalid config file.
    Remove the file when a test is finished with it.
    """
    data_dir = pathlib.Path(str(tmpdir))
    invalid_file = data_dir.joinpath('invalid')
    with invalid_file.open('w') as f:
        f.write('this is invalid')

    def tearDown():
        if invalid_file.exists():
            invalid_file.unlink()

    request.addfinalizer(tearDown)
    return invalid_file