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.

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.

Parameters:
__init__(attempts, *args)[source]#

Raise LibVCSException exception with message including attempts tried.

Parameters:
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.

Return type:

bool

Parameters:
  • collection_path (Path) –

  • config (Config) –

libvcs.pytest_plugin.home_path(tmp_path_factory)[source]#

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

Return type:

Path

Parameters:

tmp_path_factory (TempPathFactory) –

libvcs.pytest_plugin.home_user_name()[source]#

Return default username to set for user_path() fixture.

Return type:

str

libvcs.pytest_plugin.user_path(home_path, home_user_name)[source]#

Return user’s home directory, pytest fixture.

Return type:

Path

Parameters:
  • home_path (Path) –

  • home_user_name (str) –

libvcs.pytest_plugin.set_home(monkeypatch, user_path)[source]#

Set home directory, pytest fixture.

Return type:

None

Parameters:
libvcs.pytest_plugin.gitconfig(user_path, set_home)[source]#

Return git configuration, pytest fixture.

Return type:

Path

Parameters:
  • user_path (Path) –

  • set_home (Path) –

libvcs.pytest_plugin.hgconfig(user_path, set_home)[source]#

Return Mercurial configuration, pytest fixture.

Return type:

Path

Parameters:
  • user_path (Path) –

  • set_home (Path) –

libvcs.pytest_plugin.projects_path(user_path, request)[source]#

User’s local checkouts and clones. Emphemeral directory.

Return type:

Path

Parameters:
libvcs.pytest_plugin.remote_repos_path(user_path, request)[source]#

System’s remote (file-based) repos to clone andpush to. Emphemeral directory.

Return type:

Path

Parameters:
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.

Return type:

str

Parameters:
  • remote_repos_path (Path) –

  • max_retries (int) –

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]#
Return type:

Path

Parameters:
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:

CreateRepoPytestFixtureFn

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.

Return type:

None

Parameters:

remote_repo_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.

Return type:

Path

Parameters:

remote_repos_path (Path) –

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.

Return type:

Path

Parameters:
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.

Return type:

None

Parameters:

remote_repo_path (Path) –

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:

CreateRepoPytestFixtureFn

Parameters:

remote_repos_path (Path) –

libvcs.pytest_plugin.svn_remote_repo(remote_repos_path)[source]#

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

Return type:

Path

Parameters:

remote_repos_path (Path) –

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.

Return type:

Path

Parameters:
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.

Return type:

None

Parameters:

remote_repo_path (Path) –

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:

CreateRepoPytestFixtureFn

Parameters:
  • remote_repos_path (Path) –

  • hgconfig (Path) –

  • set_home (Path) –

libvcs.pytest_plugin.hg_remote_repo(remote_repos_path, hgconfig)[source]#

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

Return type:

Path

Parameters:
  • remote_repos_path (Path) –

  • hgconfig (Path) –

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.

Return type:

GitSync

Parameters:
  • projects_path (Path) –

  • git_remote_repo (Path) –

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.

Return type:

HgSync

Parameters:
  • projects_path (Path) –

  • hg_remote_repo (Path) –

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.

Return type:

SvnSync

Parameters:
  • projects_path (Path) –

  • svn_remote_repo (Path) –

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:

None

Parameters: