def METHOD_NAME(
    file: str | Path,
    directory: str | Path | None = None,
    content: str | None = None,
    init_content: str = "",
    subdir: str | None = None,
) -> Path:
    base = tmp_project_dir
    if directory:
        base /= Path(Path(directory) / subdir) if subdir else Path(directory)
        base.mkdir(parents=True)
        base.joinpath("__init__.py").write_text(init_content)
    tmp_app_file = base / file
    tmp_app_file.write_text(content or APP_FILE_CONTENT)
    if directory:
        request.addfinalizer(lambda: rmtree(directory))
        request.addfinalizer(
            lambda: _purge_module(
                [directory, _path_to_dotted_path(tmp_app_file.relative_to(Path.cwd()))], tmp_app_file  # type: ignore[list-item]
            )
        )
    else:
        request.addfinalizer(tmp_app_file.unlink)
        request.addfinalizer(lambda: _purge_module([str(file).replace(".py", "")], tmp_app_file))
    return tmp_app_file