Skip to content

Commit b398883

Browse files
committed
Add monkeypatching of env vars and date to temp_repo fixture.
1 parent fe97e96 commit b398883

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/conftest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#
2222

2323
# stdlib
24+
import datetime
2425
import os
2526
import pathlib
2627
import secrets
@@ -29,9 +30,11 @@
2930
# 3rd party
3031
import jinja2
3132
import pytest
33+
from dulwich.config import StackedConfig
3234
from southwark.repo import Repo
3335

3436
# this package
37+
import repo_helper.utils
3538
from repo_helper.files.linting import lint_fix_list, lint_warn_list
3639
from repo_helper.templates import template_dir
3740

@@ -97,10 +100,21 @@ def original_datadir(request):
97100

98101

99102
@pytest.fixture()
100-
def temp_repo(temp_empty_repo) -> Repo:
103+
def temp_repo(temp_empty_repo, monkeypatch) -> Repo:
101104
(temp_empty_repo.path / "repo_helper.yml").write_text(
102105
(pathlib.Path(__file__).parent / "repo_helper.yml_").read_text()
103106
)
107+
108+
# Monkeypatch dulwich so it doesn't try to use the global config.
109+
monkeypatch.setattr(StackedConfig, "default_backends", lambda *args: [], raising=True)
110+
monkeypatch.setenv("GIT_COMMITTER_NAME", "Guido")
111+
monkeypatch.setenv("GIT_COMMITTER_EMAIL", "[email protected]")
112+
monkeypatch.setenv("GIT_AUTHOR_NAME", "Guido")
113+
monkeypatch.setenv("GIT_AUTHOR_EMAIL", "[email protected]")
114+
115+
FAKE_DATE = datetime.date(2020, 7, 25)
116+
monkeypatch.setattr(repo_helper.utils, "today", FAKE_DATE)
117+
104118
return temp_empty_repo
105119

106120

0 commit comments

Comments
 (0)