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.

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.pytest_ignore_collect(collection_path, config)[source]#
Return type:

bool

Parameters:
  • collection_path (Path) –

  • config (Config) –

libvcs.pytest_plugin.home_path(tmp_path_factory)[source]#
Return type:

Path

Parameters:

tmp_path_factory (TempPathFactory) –

libvcs.pytest_plugin.home_user_name()[source]#

Default username to set for user_path() fixture.

Return type:

str

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

Path

Parameters:
  • home_path (Path) –

  • home_user_name (str) –

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

None

Parameters:
  • monkeypatch (MonkeyPatch) –

  • user_path (Path) –

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

Path

Parameters:
  • user_path (Path) –

  • set_home (Path) –

libvcs.pytest_plugin.hgconfig(user_path, set_home)[source]#
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:
  • 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:

Path

Parameters:
  • user_path (Path) –

  • request (FixtureRequest) –

libvcs.pytest_plugin.unique_repo_name(remote_repos_path, max_retries=15)[source]#
Return type:

str

Parameters:
  • remote_repos_path (Path) –

  • max_retries (int) –

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

Path

Parameters:
libvcs.pytest_plugin.create_git_remote_repo(remote_repos_path)[source]#

Factory. Create git remote repo to for clone / push purposes

Return type:

CreateProjectCallbackFixtureProtocol

Parameters:

remote_repos_path (Path) –

libvcs.pytest_plugin.git_remote_repo_single_commit_post_init(remote_repo_path)[source]#
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.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:

CreateProjectCallbackFixtureProtocol

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

CreateProjectCallbackFixtureProtocol

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

None

Parameters:

`