Provide a gitconfig sandbox for testing
Project description
pytest-gitconfig
Provide a gitconfig sandbox for testing
Getting started
Install pytest-gitconfig:
# pip
pip install pytest-gitconfig
# pipenv
pipenv install pytest-gitconfig
# PDM
pdm add pytest-gitconfig
Then in your conftest.py:
# All tests are using the sandboxed gitconfig
pytestmark = pytest.mark.usefixtures("gitconfig")
or if you want to customize or depend on it
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pytest_gitconfig import GitConfig
@pytest.fixture
def git_user_name() -> str:
return "John Doe"
@pytest.fixture
def fixture_depending_on_gitconfig(gitconfig: GitConfig) -> Whatever:
# You can set values
gitconfig.set(group={key: value}) # nested key-value form
gitconfig.set(**{"othersome.key": True}) # dotted keys form
# Or read them
data = gitconfig.get("path.to.key")
# If you need the path to the gitconfig file
GIT_CONFIG_GLOBAL = str(gitconfig)
return whatever
Provided fixtures
All fixtures are session-scoped.
gitconfig -> pytest_gitconfig.GitConfig
This is the main fixture which is creating a new and clean git config file for the test session.
By default, it will set 3 settings:
user.nameuser.emailinit.defaultBranch
The fixture when required provide a pytest_gitconfig.GitConfig object with the following methods:
gitconfig.set()accepting either adictwith the parsed data sections or key-values with dotted key names.gitconfig.get()to get a setting given its dotted key.
It works by monkeypatching the GIT_CONFIG_GLOBAL environment variable.
So, if you rely on this in a context where os.environ is ignored, you should patch it yourself using this fixture.
git_user_name -> str
Provide the initial user.name setting. By default pytest_gitconfig.DEFAULT_GIT_USER_NAME.
Override to provide a different initial value.
git_user_email -> str
Provide the initial user.email setting. By default pytest_gitconfig.DEFAULT_GIT_USER_EMAIL.
Override to provide a different initial value.
git_init_default_branch -> str
Provide the initial init.defaultBranch setting. By default pytest_gitconfig.DEFAULT_GIT_BRANCH (main).
Override to provide a different initial value.
sessionpatch -> pytest.MonkeyPatch
A pytest.MonkeyPatch session instance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_gitconfig-0.4.0.tar.gz.
File metadata
- Download URL: pytest_gitconfig-0.4.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.9.3 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fda91056d5f1370639d72ac59927aa6eaa4585999dd7976f05019f26957d146
|
|
| MD5 |
dd82b172fd8f1c97ed95429ef62cc1d1
|
|
| BLAKE2b-256 |
dff2e48ae93a8bef9f87710ef456fc671ea23e645e0753a0c8070d27ec23322c
|
File details
Details for the file pytest_gitconfig-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pytest_gitconfig-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.9.3 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec8bf2cd7bd5685205980f733a1ed38a8663c01a61fe83be79dd1d1dd03fad0e
|
|
| MD5 |
ea96c59f231fdfa42af7036f1584326a
|
|
| BLAKE2b-256 |
23859b5c66c57d4774983b6f8376c247069e265b07fc87f4cdb866b848a39e16
|