Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,27 @@

from collections.abc import Callable
import json
import os
from pathlib import Path
from typing import Any

import pytest

_FIXTURE_DIR = Path(__file__).resolve().parent / "fixtures"
GIT_ENVIRONMENT_PREFIX = "GIT_"


def pytest_configure(config: pytest.Config) -> None:
"""Remove every ``GIT_*`` variable before any fixture or xdist worker starts.

A hook run by ``git commit -a`` exports an absolute ``GIT_INDEX_FILE`` that
points at this repository's ``index.lock``; a test that runs git in a
temporary repository would otherwise read and write that index instead.
"""
for name in [
name for name in os.environ if name.startswith(GIT_ENVIRONMENT_PREFIX)
]:
del os.environ[name]


def _load_json_fixture(name: str) -> dict[str, Any]:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_git_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2026 DataRobot, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests run free of the environment a calling git process exports."""

from __future__ import annotations

import os


def test_tests_see_no_git_environment_variables() -> None:
"""A hook run by ``git commit -a`` exports ``GIT_INDEX_FILE``; tests never see it."""
assert [name for name in os.environ if name.startswith("GIT_")] == []
Loading