pytest Plugin¶
Recommended fixtures¶
These fixtures are the usual starting point when enabling the plugin:
set_vcs_gitconfigandset_vcs_hgconfigapply stable VCS configuration.vcs_name,vcs_email, andvcs_userlet you override commit identity defaults.git_commit_envvarshelps when Git ignoresGIT_CONFIGin a subprocess-heavy test.
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
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.
- Used by:
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.
- Used by:
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:
- Used by:
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:
- Used by:
For some reason, GIT_CONFIG via {func}`set_vcs_gitconfig` doesn’t work for git commit.
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:
- Used by:
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:
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.
- Depends on:
- Used by:
projects_path,remote_repos_path,set_home,vcs_gitconfig,vcs_hgconfig
Set home directory, pytest fixture.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
Set git configuration.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
Set Mercurial configuration.
- Depends on:
- Used by:
User’s local checkouts and clones. Ephemeral directory.
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.
- Depends on:
- Used by:
create_git_remote_bare_repo,create_git_remote_repo,create_hg_remote_repo,create_svn_remote_repo,git_repo,hg_remote_repo,hg_repo,svn_repo
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.
- Depends on:
- Used by:
empty_git_bare_repo_path,empty_git_repo_path,empty_hg_repo_path,empty_svn_repo_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:
- Used by:
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.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
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.
- Depends on:
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.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
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:
- Used by:
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.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
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:
- Used by:
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:
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:
- Used by:
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.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
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.
- Depends on:
- Used by:
Return an isolated git clone of the remote repo, one per test.
- Depends on:
remote_repos_path,projects_path,git_remote_repo,set_vcs_gitconfig,set_home
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).
Return an isolated hg clone of the remote repo, one per test.
- Depends on:
remote_repos_path,projects_path,hg_remote_repo,set_vcs_hgconfig
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).
Return an isolated svn checkout of the remote repo, one per test.
- Depends on:
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).
Harness pytest fixtures to pytest’s doctest namespace.