Skip to content

Commit

Permalink
use decoupled but minimal git env in tests
Browse files Browse the repository at this point in the history
When running in bare CI environments, the git tool is usually not
configured yet. By that, common operations like 'git commit' cannot be
executed in our tests. However, when running in local environments, the
git configuration might vary, making it hard to write robust test code.

This patch enhances our default test fixture to always prepare a stable,
minimal and decoupled environment. By that, tests that use git can be
written without needing the git setup boilerplate code.

Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Apr 30, 2024
1 parent d735a4a commit 2b731d9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# SOFTWARE.

import pytest
import os

ENVVARS_KAS = [
'KAS_WORK_DIR',
Expand All @@ -36,14 +37,28 @@
'SSH_AUTH_SOCK',
]

ENVVARS_TOOLS = [
'EMAIL'
]


@pytest.fixture
def monkeykas(monkeypatch, tmpdir):
for var in ENVVARS_KAS:
for var in ENVVARS_KAS + ENVVARS_TOOLS:
monkeypatch.delenv(var, raising=False)
# Set HOME to a temporary directory
homedir = tmpdir / '_home'
homedir.mkdir()
monkeypatch.setenv('HOME', str(homedir))

# remove all git related variables
for var in os.environ.keys():
if var.startswith('GIT_'):
monkeypatch.delenv(var)
# provide minimal git environment
monkeypatch.setenv('GIT_AUTHOR_NAME', 'kas')
monkeypatch.setenv('GIT_AUTHOR_EMAIL', '[email protected]')
monkeypatch.setenv('GIT_COMMITTER_NAME', 'kas')
monkeypatch.setenv('GIT_COMMITTER_EMAIL', '[email protected]')

yield monkeypatch

0 comments on commit 2b731d9

Please sign in to comment.