pytest Plugin¶

Bootstrapping in conftest.py¶

Keep autouse setup explicit in your own conftest.py instead of having the plugin force global side effects.

>>> import pytest
>>> @pytest.fixture(autouse=True)
... def setup(
...     set_home: None,
...     set_vcs_gitconfig: None,
...     set_vcs_hgconfig: None,
... ) -> None:
...     pass

Repository isolation¶

git_repo, hg_repo, and svn_repo hand each test its own clone. The remote is built once and cached for the session, then copied for every consumer, so a test can commit, add remotes, or rewrite history without affecting any other test — and the fixtures stay safe under parallel runs (pytest-xdist).

libvcs ships a pytest plugin for creating isolated Git, Mercurial, and Subversion repositories during tests.

Install

$ pip install libvcs

Note

pytest auto-detects this plugin through the pytest11 entry point. Its fixtures are available without extra conftest.py imports.

For real-world usage examples, see the libvcs test suite.

Use these fixtures when your tests need disposable repositories, config files, and home-directory setup without repeating bootstrap code in every suite.

Fixture Reference

fixture libvcs.pytest_plugin.vcs_name str
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.vcs_name str
¶

Return default VCS name.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.vcs_email str
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.vcs_email str
¶

Return default VCS email.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.vcs_user str
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.vcs_user str
¶

Return default VCS user.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

vcs_name, vcs_email

Used by:

vcs_hgconfig

fixture libvcs.pytest_plugin.git_commit_envvars GitCommitEnvVars
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.git_commit_envvars GitCommitEnvVars
¶

Return environment variables for git commit.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

vcs_name, vcs_email

Used by:

git_remote_repo

For some reason, GIT_CONFIG via {func}`set_vcs_gitconfig` doesn’t work for git commit.

fixture libvcs.pytest_plugin.home_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.home_path Path
¶

Return temporary directory to use as user’s home path, pytest fixture.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

tmp_path_factory

Used by:

user_path

fixture libvcs.pytest_plugin.home_user_name str
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.home_user_name str
¶

Return default username to set for user_path() fixture.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Used by:

user_path

fixture libvcs.pytest_plugin.user_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.user_path Path
¶

Return user’s home directory, pytest fixture.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.set_home None
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.set_home None
¶

Set home directory, pytest fixture.

fixture libvcs.pytest_plugin.vcs_gitconfig Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.vcs_gitconfig Path
¶

Return git configuration, pytest fixture.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.set_vcs_gitconfig Path
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.set_vcs_gitconfig Path
¶

Set git configuration.

Depends on:

monkeypatch, vcs_gitconfig

Used by:

git_repo

fixture libvcs.pytest_plugin.vcs_hgconfig Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.vcs_hgconfig Path
¶

Return Mercurial configuration.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.set_vcs_hgconfig Path
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.set_vcs_hgconfig Path
¶

Set Mercurial configuration.

Depends on:

monkeypatch, vcs_hgconfig

Used by:

hg_repo

fixture libvcs.pytest_plugin.projects_path Path
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.projects_path Path
¶

User’s local checkouts and clones. Ephemeral directory.

Depends on:

user_path, request

Used by:

git_repo, hg_repo, svn_repo

fixture libvcs.pytest_plugin.remote_repos_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.remote_repos_path Path
¶

System’s remote (file-based) repos to clone and push to. Ephemeral directory.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.libvcs_test_cache_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.libvcs_test_cache_path Path
¶

Return temporary directory to use as cache path for libvcs tests.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.empty_git_repo_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_git_repo_path Path
¶

Return temporary directory to use for master-copy of a git repo.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

libvcs_test_cache_path

Used by:

empty_git_repo

fixture libvcs.pytest_plugin.empty_git_bare_repo_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_git_bare_repo_path Path
¶

Return temporary directory to use for master-copy of a bare git repo.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.empty_git_bare_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_git_bare_repo Path
¶

Return factory to create git remote repo to for clone / push purposes.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.empty_git_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_git_repo Path
¶

Return factory to create git remote repo to for clone / push purposes.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.create_git_remote_bare_repo CreateRepoFn
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.create_git_remote_bare_repo CreateRepoFn
¶

Return factory to create git remote repo to for clone / push purposes.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.create_git_remote_repo CreateRepoFn
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.create_git_remote_repo CreateRepoFn
¶

Return factory to create git remote repo to for clone / push purposes.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.git_remote_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.git_remote_repo Path
¶

Session-scoped remote Git repository with one commit, as a clone source.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.empty_svn_repo_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_svn_repo_path Path
¶

Return temporary directory to use for master-copy of a svn repo.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

libvcs_test_cache_path

Used by:

empty_svn_repo

fixture libvcs.pytest_plugin.empty_svn_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_svn_repo Path
¶

Return factory to create svn remote repo to for clone / push purposes.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.create_svn_remote_repo CreateRepoFn
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.create_svn_remote_repo CreateRepoFn
¶

Pre-made svn repo, bare, used as a file:// remote to checkout and commit to.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.svn_remote_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.svn_remote_repo Path
¶

Pre-made. Local file:// based SVN server.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

create_svn_remote_repo

Used by:

svn_repo

fixture libvcs.pytest_plugin.svn_remote_repo_with_files Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.svn_remote_repo_with_files Path
¶

Pre-made. Local file:// based SVN server.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.empty_hg_repo_path Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_hg_repo_path Path
¶

Return temporary directory to use for master-copy of a hg repo.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

Depends on:

libvcs_test_cache_path

Used by:

empty_hg_repo

fixture libvcs.pytest_plugin.empty_hg_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.empty_hg_repo Path
¶

Return factory to create hg remote repo to for clone / push purposes.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.create_hg_remote_repo CreateRepoFn
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.create_hg_remote_repo CreateRepoFn
¶

Pre-made hg repo, bare, used as a file:// remote to checkout and commit to.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.hg_remote_repo Path
¶
session fixture[source]
session fixture[source]
fixture libvcs.pytest_plugin.hg_remote_repo Path
¶

Pre-made, file-based repo for push and pull.

Note

Created once per test session and shared across all tests. Requesting this fixture does not create a new instance per test.

fixture libvcs.pytest_plugin.git_repo GitSync
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.git_repo GitSync
¶

Return an isolated git clone of the remote repo, one per test.

Every consumer gets its own checkout under the user’s projects dir, copied from a session-cached master. A test may freely mutate it (commit, add remotes, switch branches) without affecting any other test, so the fixture is safe under parallel runs (pytest-xdist).

fixture libvcs.pytest_plugin.hg_repo HgSync
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.hg_repo HgSync
¶

Return an isolated hg clone of the remote repo, one per test.

Every consumer gets its own checkout under the user’s projects dir, copied from a session-cached master. A test may freely mutate it without affecting any other test, so the fixture is safe under parallel runs (pytest-xdist).

fixture libvcs.pytest_plugin.svn_repo SvnSync
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.svn_repo SvnSync
¶

Return an isolated svn checkout of the remote repo, one per test.

Every consumer gets its own working copy under the user’s projects dir, copied from a session-cached master. A test may freely mutate it without affecting any other test, so the fixture is safe under parallel runs (pytest-xdist).

fixture libvcs.pytest_plugin.add_doctest_fixtures None
¶
fixture[source]
fixture[source]
fixture libvcs.pytest_plugin.add_doctest_fixtures None
¶

Harness pytest fixtures to pytest’s doctest namespace.

Depends on:

request, doctest_namespace, tmp_path, set_home

Types¶

libvcs.pytest_plugin.GitCommitEnvVars
¶
data
data
libvcs.pytest_plugin.GitCommitEnvVars
¶

Environment variable mapping passed to git commit subprocess calls.

alias of dict[str, str]

class libvcs.pytest_plugin.CreateRepoFn
¶
class libvcs.pytest_plugin.CreateRepoFn
¶

Bases: Protocol

Typing for VCS pytest fixture callback.

class libvcs.pytest_plugin.CreateRepoPostInitFn
¶
class libvcs.pytest_plugin.CreateRepoPostInitFn
¶

Bases: Protocol

Typing for VCS repo creation callback.