Skip to content

Commit 99961c3

Browse files
committed
docs(pytest_plugin): document fixture isolation
why: The git_repo/hg_repo/svn_repo per-test isolation guarantee lived only in inline comments, so downstream consumers (e.g. vcspull) could not see it from the docstrings or rendered docs. A few neighboring fixture docs were also stale. what: - Document the per-test isolation contract in the three repo fixtures' docstrings and add a "Repository isolation" note to the plugin doc page - Correct the inaccurate "session-scoped" card in docs/api/index.md - Fix the git_remote_repo docstring and the "Emphemeral" typo
1 parent 67fa068 commit 99961c3

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

docs/api/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ One call to fetch or create a working copy.
3939
:::{grid-item-card} pytest Plugin
4040
:link: /api/pytest-plugin
4141
:link-type: doc
42-
Session-scoped fixtures for Git, SVN, and Mercurial
43-
repositories. Drop-in test isolation.
42+
Per-test isolated Git, SVN, and Mercurial repository fixtures,
43+
backed by session-cached remotes. Drop-in test isolation.
4444
:::
4545

4646
::::

docs/api/pytest-plugin.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def setup(
4040
) -> None:
4141
pass
4242
```
43+
44+
## Repository isolation
45+
46+
{fixture}`git_repo`, {fixture}`hg_repo`, and {fixture}`svn_repo` hand each test
47+
its own clone. The remote is built once and cached for the session, then copied
48+
for every consumer, so a test can commit, add remotes, or rewrite history
49+
without affecting any other test — and the fixtures stay safe under parallel
50+
runs (`pytest-xdist`).
4351
:::
4452

4553
## Types

src/libvcs/pytest_plugin.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def projects_path(
238238
user_path: pathlib.Path,
239239
request: pytest.FixtureRequest,
240240
) -> pathlib.Path:
241-
"""User's local checkouts and clones. Emphemeral directory."""
241+
"""User's local checkouts and clones. Ephemeral directory."""
242242
path = user_path / "projects"
243243
path.mkdir(exist_ok=True)
244244

@@ -254,7 +254,7 @@ def remote_repos_path(
254254
user_path: pathlib.Path,
255255
request: pytest.FixtureRequest,
256256
) -> pathlib.Path:
257-
"""System's remote (file-based) repos to clone and push to. Emphemeral directory."""
257+
"""System's remote (file-based) repos to clone and push to. Ephemeral directory."""
258258
path = user_path / "remote_repos"
259259
path.mkdir(exist_ok=True)
260260

@@ -474,7 +474,7 @@ def git_remote_repo(
474474
vcs_gitconfig: pathlib.Path,
475475
git_commit_envvars: GitCommitEnvVars,
476476
) -> pathlib.Path:
477-
"""Copy the session-scoped Git repository to a temporary directory."""
477+
"""Session-scoped remote Git repository with one commit, as a clone source."""
478478
_skip_if_git_missing()
479479
# TODO: Cache the effect of of this in a session-based repo
480480
repo_path = create_git_remote_repo()
@@ -714,7 +714,13 @@ def git_repo(
714714
set_vcs_gitconfig: pathlib.Path,
715715
set_home: None, # Needed for child processes (e.g. submodules)
716716
) -> GitSync:
717-
"""Pre-made git clone of remote repo checked out to user's projects dir."""
717+
"""Return an isolated git clone of the remote repo, one per test.
718+
719+
Every consumer gets its own checkout under the user's projects dir, copied
720+
from a session-cached master. A test may freely mutate it (commit, add
721+
remotes, switch branches) without affecting any other test, so the fixture
722+
is safe under parallel runs (``pytest-xdist``).
723+
"""
718724
remote_repo_name = unique_repo_name(remote_repos_path=projects_path)
719725
new_checkout_path = projects_path / remote_repo_name
720726
master_copy = remote_repos_path / "git_repo"
@@ -749,7 +755,12 @@ def hg_repo(
749755
hg_remote_repo: pathlib.Path,
750756
set_vcs_hgconfig: pathlib.Path,
751757
) -> HgSync:
752-
"""Pre-made hg clone of remote repo checked out to user's projects dir."""
758+
"""Return an isolated hg clone of the remote repo, one per test.
759+
760+
Every consumer gets its own checkout under the user's projects dir, copied
761+
from a session-cached master. A test may freely mutate it without affecting
762+
any other test, so the fixture is safe under parallel runs (``pytest-xdist``).
763+
"""
753764
remote_repo_name = unique_repo_name(remote_repos_path=projects_path)
754765
new_checkout_path = projects_path / remote_repo_name
755766
master_copy = remote_repos_path / "hg_repo"
@@ -776,7 +787,13 @@ def svn_repo(
776787
projects_path: pathlib.Path,
777788
svn_remote_repo: pathlib.Path,
778789
) -> SvnSync:
779-
"""Pre-made svn clone of remote repo checked out to user's projects dir."""
790+
"""Return an isolated svn checkout of the remote repo, one per test.
791+
792+
Every consumer gets its own working copy under the user's projects dir,
793+
copied from a session-cached master. A test may freely mutate it without
794+
affecting any other test, so the fixture is safe under parallel runs
795+
(``pytest-xdist``).
796+
"""
780797
remote_repo_name = unique_repo_name(remote_repos_path=projects_path)
781798
new_checkout_path = projects_path / remote_repo_name
782799
master_copy = remote_repos_path / "svn_repo"

0 commit comments

Comments
 (0)