From d5556eab1a11b173db51d5f4348024ec5ec94198 Mon Sep 17 00:00:00 2001 From: quotentiroler Date: Thu, 15 Oct 2026 02:22:50 +0200 Subject: [PATCH] Build the reflex-release test repository once per session The `repo` fixture created a fresh git repository for each of the ~480 reflex_release tests: `git remote get-url` (via towncrier_config_toml), `git init`, `git add -A` and `git commit`. A session-scoped `repo_template` fixture now builds that repository once and `repo` copies it into `tmp_path`, so each test still gets its own isolated repository with identical contents and history shape. Measured locally (Windows, Python 3.14): - fixture: 510 ms -> 73 ms per test - tests/units/reflex_release: 248.6 s -> 116.5 s, setup phase ~187 s -> 33 s On Linux (python:3.12 container) the fixture goes 27 ms -> 16 ms, about 5 s per suite run. The same 480 test ids are collected before and after and all pass. --- tests/units/reflex_release/conftest.py | 43 ++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) 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