def METHOD_NAME(tmpdir, monkeypatch, name, existing_files, expected):
    """
    Ensure the DeferredFileWriter backs up existing files correctly, and at the
    correct moment
    """
    monkeypatch.chdir(tmpdir)
    for idx, file in enumerate(existing_files):
        with open(file, 'w') as handle:
            handle.write(str(idx))
    writer = DeferredFileWriter()
    with writer.open(name, 'w') as handle:
        handle.write("new {}".format(name))
    writer.write()
    assert Path(name).is_file()
    with open(name) as file:
        assert file.read() == "new {}".format(name)
    for idx, name in enumerate(expected):
        assert Path(name).is_file()
        with open(name) as file:
            assert file.read() == str(idx)