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 very 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 withou. 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 fixtures. Live inside libvcs for doctest.
- class libvcs.pytest_plugin.RandomStrSequence(characters='abcdefghijklmnopqrstuvwxyz0123456789_')[source]#
Bases:
object
- Parameters:
characters (str) β
- libvcs.pytest_plugin.home_path(tmp_path_factory)[source]#
- Return type:
- Parameters:
tmp_path_factory (TempPathFactory) β
- libvcs.pytest_plugin.home_user_name()[source]#
Default username to set for
user_path()
fixture.- Return type:
- libvcs.pytest_plugin.set_home(monkeypatch, user_path)[source]#
- Return type:
- Parameters:
monkeypatch (MonkeyPatch) β
user_path (Path) β
- 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) β
- class libvcs.pytest_plugin.CreateProjectCallbackProtocol(*args, **kwargs)[source]#
Bases:
Protocol
- _abc_impl = <_abc._abc_data object>#
- _is_protocol = True#
- _is_runtime_protocol = False#
- class libvcs.pytest_plugin.CreateProjectCallbackFixtureProtocol(*args, **kwargs)[source]#
Bases:
Protocol
- _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]#
Factory. Create git remote repo to for clone / push purposes
- Return type:
- Parameters:
remote_repos_path (Path) β
- 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.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.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]#
- Return type:
- Parameters:
request (FixtureRequest) β
tmp_path (Path) β
set_home (Path) β
gitconfig (Path) β
create_git_remote_repo (CreateProjectCallbackFixtureProtocol) β
create_svn_remote_repo (CreateProjectCallbackFixtureProtocol) β
create_hg_remote_repo (CreateProjectCallbackFixtureProtocol) β
git_repo (Path) β