pytest
plugin#
Create git, svn, and hg repos on the fly in pytest.
See also
Using libvcs?
Do you want more flexbility? Correctness? Power? Defaults changed? Connect with us on the tracker, we want to know your case, we wonβt stabilize APIs until weβre sure everything is by the book.
Usage#
Install libvcs
via the python package manager of your choosing, e.g.
$ pip install libvcs
The pytest plugin will automatically be detected via pytest, and the fixtures will be added.
Fixtures#
pytest-vcs
works through providing pytest fixtures - so read up on
those!
The pluginβs fixtures guarantee a fresh git repository every test.
Recommended fixtures#
These are fixtures are automatically used when the plugin is enabled and pytest
is ran.
Creating temporary, test directories for:
/home/
(home_path()
)/home/${user}
(user_path()
)
Setting your home directory
Patch
$HOME
to point touser_path()
(set_home()
)
Set default configuration
.gitconfig
, viagitconfig()
:.hgrc
, viahgconfig()
:
These are set to ensure you can correctly clone and create repositories without. without extra warnings.
Bootstrapping pytest in your conftest.py
#
The most common scenario is you will want to configure the above fixtures with autouse
.
Why doesnβt the plugin automatically add them? Itβs part of being a decent pytest plugin and python package: explicitness.
Setting a temporary home directory#
import pytest
@pytest.fixture(autouse=True)
def setup(
set_home: None,
):
pass
See examples#
View libvcsβs own tests/
API reference#
pytest plugin for VCS Repository testing and management.
- exception libvcs.pytest_plugin.MaxUniqueRepoAttemptsExceeded(attempts, *args)[source]#
Bases:
LibVCSException
Raised when exceeded threshold of attempts to find a unique repo destination.
Raise LibVCSException exception with message including attempts tried.
- __init__(attempts, *args)[source]#
Raise LibVCSException exception with message including attempts tried.
- add_note()#
Exception.add_note(note) β add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) β set self.__traceback__ to tb and return self.
- class libvcs.pytest_plugin.RandomStrSequence(characters='abcdefghijklmnopqrstuvwxyz0123456789_')[source]#
Bases:
object
Create a random string sequence.
- Parameters:
characters (str) β
- libvcs.pytest_plugin.pytest_ignore_collect(collection_path, config)[source]#
Skip tests if VCS binaries are missing.
- libvcs.pytest_plugin.home_path(tmp_path_factory)[source]#
Return temporary directory to use as userβs home path, pytest fixture.
- Return type:
- Parameters:
tmp_path_factory (TempPathFactory) β
- libvcs.pytest_plugin.home_user_name()[source]#
Return default username to set for
user_path()
fixture.- Return type:
- libvcs.pytest_plugin.user_path(home_path, home_user_name)[source]#
Return userβs home directory, pytest fixture.
- libvcs.pytest_plugin.set_home(monkeypatch, user_path)[source]#
Set home directory, pytest fixture.
- Return type:
- Parameters:
monkeypatch (MonkeyPatch) β
user_path (Path) β
- libvcs.pytest_plugin.gitconfig(user_path, set_home)[source]#
Return git configuration, pytest fixture.
- libvcs.pytest_plugin.hgconfig(user_path, set_home)[source]#
Return Mercurial configuration, pytest fixture.
- libvcs.pytest_plugin.projects_path(user_path, request)[source]#
Userβs local checkouts and clones. Emphemeral directory.
- Return type:
- Parameters:
user_path (Path) β
request (FixtureRequest) β
- libvcs.pytest_plugin.remote_repos_path(user_path, request)[source]#
Systemβs remote (file-based) repos to clone andpush to. Emphemeral directory.
- Return type:
- Parameters:
user_path (Path) β
request (FixtureRequest) β
- libvcs.pytest_plugin.unique_repo_name(remote_repos_path, max_retries=15)[source]#
Attempt to find and return a unique repo named based on path.
- class libvcs.pytest_plugin.CreateRepoPostInitFn(*args, **kwargs)[source]#
Bases:
Protocol
Typing for VCS repo creation callback.
- _abc_impl = <_abc._abc_data object>#
- _is_protocol = True#
- _is_runtime_protocol = False#
- class libvcs.pytest_plugin.CreateRepoPytestFixtureFn(*args, **kwargs)[source]#
Bases:
Protocol
Typing for VCS pytest fixture callback.
- _abc_impl = <_abc._abc_data object>#
- _is_protocol = True#
- _is_runtime_protocol = False#
- libvcs.pytest_plugin._create_git_remote_repo(remote_repos_path, remote_repo_name, remote_repo_post_init=None, init_cmd_args=['--bare'])[source]#
- libvcs.pytest_plugin.create_git_remote_repo(remote_repos_path)[source]#
Return factory to create git remote repo to for clone / push purposes.
- Return type:
- Parameters:
remote_repos_path (Path) β
- libvcs.pytest_plugin.git_remote_repo_single_commit_post_init(remote_repo_path)[source]#
Post-initialization: Create a test git repo with a single commit.
- libvcs.pytest_plugin.git_remote_repo(remote_repos_path)[source]#
Pre-made git repo w/ 1 commit, used as a file:// remote to clone and push to.
- libvcs.pytest_plugin._create_svn_remote_repo(remote_repos_path, remote_repo_name, remote_repo_post_init=None, init_cmd_args=None)[source]#
Create a test SVN repo to for checkout / commit purposes.
- libvcs.pytest_plugin.svn_remote_repo_single_commit_post_init(remote_repo_path)[source]#
Post-initialization: Create a test SVN repo with a single commit.
- libvcs.pytest_plugin.create_svn_remote_repo(remote_repos_path)[source]#
Pre-made svn repo, bare, used as a file:// remote to checkout and commit to.
- Return type:
- Parameters:
remote_repos_path (Path) β
- libvcs.pytest_plugin.svn_remote_repo(remote_repos_path)[source]#
Pre-made. Local file:// based SVN server.
- libvcs.pytest_plugin._create_hg_remote_repo(remote_repos_path, remote_repo_name, remote_repo_post_init=None, init_cmd_args=None)[source]#
Create a test hg repo to for checkout / commit purposes.
- libvcs.pytest_plugin.hg_remote_repo_single_commit_post_init(remote_repo_path)[source]#
Post-initialization: Create a test mercurial repo with a single commit.
- libvcs.pytest_plugin.create_hg_remote_repo(remote_repos_path, hgconfig, set_home)[source]#
Pre-made hg repo, bare, used as a file:// remote to checkout and commit to.
- Return type:
- Parameters:
- libvcs.pytest_plugin.hg_remote_repo(remote_repos_path, hgconfig)[source]#
Pre-made, file-based repo for push and pull.
- libvcs.pytest_plugin.git_repo(projects_path, git_remote_repo)[source]#
Pre-made git clone of remote repo checked out to userβs projects dir.
- libvcs.pytest_plugin.hg_repo(projects_path, hg_remote_repo)[source]#
Pre-made hg clone of remote repo checked out to userβs projects dir.
- libvcs.pytest_plugin.svn_repo(projects_path, svn_remote_repo)[source]#
Pre-made svn clone of remote repo checked out to userβs projects dir.
- libvcs.pytest_plugin.add_doctest_fixtures(request, doctest_namespace, tmp_path, set_home, gitconfig, create_git_remote_repo, create_svn_remote_repo, create_hg_remote_repo, git_repo)[source]#
Harness pytest fixtures to pytestβs doctest namespace.
- Return type:
- Parameters:
request (FixtureRequest) β
tmp_path (Path) β
set_home (Path) β
gitconfig (Path) β
create_git_remote_repo (CreateRepoPytestFixtureFn) β
create_svn_remote_repo (CreateRepoPytestFixtureFn) β
create_hg_remote_repo (CreateRepoPytestFixtureFn) β
git_repo (Path) β