def METHOD_NAME(file):
    # A newline should NOT be added in empty files
    contents = None
    expected = "baz=\\g<value>\n"
    with pytest.helpers.temp_file("test_file.txt", contents) as target:
        file.replace(
            path=str(target),
            pattern="#*baz=(?P<value>.*)",
            repl="baz=\\g<value>",
            append_if_not_found=True,
        )
        assert target.read_text() == expected