(pytest_plugin)=
With libvcs's pytest plugin for pytest, you can easily create Git, SVN, and Mercurial repositories on the fly.
Looking for more flexibility, correctness, or power? Need different defaults? [Connect with us] on GitHub. We'd love to hear about your use case—APIs won't be stabilized until we're confident everything meets expectations.
[connect with us]: https://github.com/vcs-python/libvcs/discussions
Install libvcs using your preferred Python package manager:
$ pip install libvcsPytest will automatically detect the plugin, and its fixtures will be available.
This pytest plugin works by providing {ref}pytest fixtures <pytest:fixtures-api>. The plugin's fixtures ensure that a fresh Git, Subversion, or Mercurial repository is available for each test. It utilizes session-scoped fixtures to cache initial repositories, improving performance across tests.
(recommended-fixtures)=
When the plugin is enabled and pytest is run, these fixtures are automatically used:
- Create temporary test directories for:
/home/({func}home_path)/home/${user}({func}user_path)
- Set the home directory:
- Patch
$HOMEto point to {func}user_pathusing ({func}set_home)
- Patch
- Create configuration files:
.gitconfigvia {func}gitconfig.hgrcvia {func}hgconfig
- Set default VCS configurations:
- Use {func}
hgconfigforHGRCPATHvia {func}set_hgconfig - Use {func}
gitconfigforGIT_CONFIGvia {func}set_gitconfig
- Use {func}
These ensure that repositories can be cloned and created without unnecessary warnings.
To configure the above fixtures with autouse=True, add them to your conftest.py file or test file, depending on the desired scope.
Why aren't these fixtures added automatically by the plugin? This design choice promotes explicitness, adhering to best practices for pytest plugins and Python packages.
To set a temporary home directory, use the {func}set_home fixture with autouse=True:
import pytest
@pytest.fixture(autouse=True)
def setup(set_home: None):
passUse the {func}set_gitconfig fixture with autouse=True:
import pytest
@pytest.fixture(autouse=True)
def setup(set_gitconfig: None):
passUse the {func}set_hgconfig fixture with autouse=True:
import pytest
@pytest.fixture(autouse=True)
def setup(set_hgconfig: None):
passFor usage examples, refer to libvcs's own tests/.
.. automodule:: libvcs.pytest_plugin
:members:
:inherited-members:
:private-members:
:show-inheritance:
:member-order: bysource