diff --git a/tests/units/reflex_release/conftest.py b/tests/units/reflex_release/conftest.py index 4aa81299537..1e1b6dde76c 100644 --- a/tests/units/reflex_release/conftest.py +++ b/tests/units/reflex_release/conftest.py @@ -2,6 +2,7 @@ from __future__ import annotations +import shutil import subprocess from collections.abc import Callable from pathlib import Path @@ -123,33 +124,49 @@ def write_custom_build(repo: Path, extra: str = "", workflow: bool = True) -> No ) -@pytest.fixture -def repo(tmp_path: Path) -> Path: - """Create a git repository with a root package and one sub-package. +@pytest.fixture(scope="session") +def repo_template(tmp_path_factory: pytest.TempPathFactory) -> Path: + """Create, once per session, the git repository that ``repo`` copies. Args: - tmp_path: The pytest temporary directory. + tmp_path_factory: The pytest temporary directory factory. Returns: - The repository root. + The template repository root. """ - (tmp_path / "src" / "mypkg").mkdir(parents=True) - (tmp_path / "packages" / "widget-core" / "src").mkdir(parents=True) - (tmp_path / "packages" / "widget-core" / "pyproject.toml").write_text( + root = tmp_path_factory.mktemp("repo-template") + (root / "src" / "mypkg").mkdir(parents=True) + (root / "packages" / "widget-core" / "src").mkdir(parents=True) + (root / "packages" / "widget-core" / "pyproject.toml").write_text( SUB_PYPROJECT.format(name="widget-core"), encoding="utf-8", ) - (tmp_path / "pyproject.toml").write_text( + (root / "pyproject.toml").write_text( ROOT_PYPROJECT + "\n[tool.reflex-release]\n" 'root-package = "mypkg"\n' - 'packages-dir = "packages"\n\n' + towncrier_config_toml(tmp_path), + 'packages-dir = "packages"\n\n' + towncrier_config_toml(root), encoding="utf-8", ) - for news in (tmp_path / "news", tmp_path / "packages" / "widget-core" / "news"): + for news in (root / "news", root / "packages" / "widget-core" / "news"): news.mkdir() (news / ".gitkeep").touch() - git(tmp_path, "init", "-q", "-b", "main") - commit_all(tmp_path, "init") + git(root, "init", "-q", "-b", "main") + commit_all(root, "init") + return root + + +@pytest.fixture +def repo(tmp_path: Path, repo_template: Path) -> Path: + """Create a git repository with a root package and one sub-package. + + Args: + tmp_path: The pytest temporary directory. + repo_template: The session's pristine repository to copy. + + Returns: + The repository root. + """ + shutil.copytree(repo_template, tmp_path, dirs_exist_ok=True) return tmp_path