Skip to content

Commit 8786696

Browse files
committed
Fix git_repo fixture when no GIT_DIR envvar
Now deleting `GIT_DIR` from environment won't crash if it wasn't there to begin with.
1 parent 0cabdbc commit 8786696

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/darker/tests/conftest.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Configuration and fixtures for the Pytest based test suite"""
22

3-
import os
43
from pathlib import Path
54
from subprocess import check_call
65
from typing import Dict, Optional
@@ -88,7 +87,10 @@ def git_repo(tmp_path, monkeypatch):
8887
"""Create a temporary Git repository and change current working directory into it"""
8988
repository = GitRepoFixture.create_repository(tmp_path)
9089
monkeypatch.chdir(tmp_path)
91-
monkeypatch.delenv("GIT_DIR")
90+
# While `GitRepoFixture.create_repository()` already deletes `GIT_*` environment
91+
# variables for any Git commands run by the fixture, let's explicitly remove
92+
# `GIT_DIR` in case a test should call Git directly:
93+
monkeypatch.delenv("GIT_DIR", raising=False)
9294
return repository
9395

9496

0 commit comments

Comments
 (0)