Skip to content

Commit c908295

Browse files
committed
tests: Sandbox Git config during tests
1 parent cc49b7c commit c908295

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ ci = [
100100
"pysource-minimize>=0.10",
101101
"pytest>=8.2",
102102
"pytest-cov>=5.0",
103+
"pytest-gitconfig>=0.8.0",
103104
"pytest-randomly>=3.15",
104105
"pytest-xdist>=3.6",
105106
"mypy>=1.10",

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
"""Configuration for the pytest test suite."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
7+
import pytest
8+
9+
if TYPE_CHECKING:
10+
from pytest_gitconfig import GitConfig
11+
12+
13+
@pytest.fixture(name="gitconfig", scope="session")
14+
def _default_gitconfig(default_gitconfig: GitConfig) -> GitConfig:
15+
default_gitconfig.set({"user.name": "My Name"})
16+
default_gitconfig.set({"user.email": "my@email.com"})
17+
return default_gitconfig

tests/test_git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
if TYPE_CHECKING:
1515
from pathlib import Path
1616

17+
from pytest_gitconfig import GitConfig
18+
1719
REPO_NAME = "my-repo"
1820
REPO_SOURCE = FIXTURES_DIR / "_repo"
1921
MODULE_NAME = "my_module"
@@ -36,7 +38,7 @@ def _copy_contents(src: Path, dst: Path) -> None:
3638

3739

3840
@pytest.fixture
39-
def git_repo(tmp_path: Path) -> Path:
41+
def git_repo(tmp_path: Path, gitconfig: GitConfig) -> Path: # noqa: ARG001
4042
"""Fixture that creates a git repo with multiple tagged versions.
4143
4244
For each directory in `tests/test_git/_repo/`
@@ -58,8 +60,6 @@ def git_repo(tmp_path: Path) -> Path:
5860
repo_path = tmp_path / REPO_NAME
5961
repo_path.mkdir()
6062
run(["git", "-C", str(repo_path), "init"], check=True)
61-
run(["git", "-C", str(repo_path), "config", "user.name", "Name"], check=True)
62-
run(["git", "-C", str(repo_path), "config", "user.email", "my@email.com"], check=True)
6363
for tagdir in REPO_SOURCE.iterdir():
6464
ver = tagdir.name
6565
_copy_contents(tagdir, repo_path)

0 commit comments

Comments
 (0)