def METHOD_NAME(file):
    # Not appending if matches
    contents = "foo=1\nbaz=42\nbar=2"
    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,
            not_found_content="baz=3",
        )
        assert target.read_text() == contents