Skip to content

Commit

Permalink
Strip environment for test_settings
Browse files Browse the repository at this point in the history
Certain variables, when set in the running environment, can make tests
fail. As environment variable names are case-insensitive by default,
it's better to start with a clean environment.

Issue: #463
  • Loading branch information
CyberTailor committed Nov 3, 2024
1 parent 91ed1c2 commit 00d1aac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from enum import IntEnum
from pathlib import Path
from typing import Any, Callable, Dict, Generic, Hashable, List, Optional, Set, Tuple, Type, TypeVar, Union
from unittest import mock

import pytest
from annotated_types import MinLen
Expand Down Expand Up @@ -68,6 +69,12 @@ class SettingWithPopulateByName(BaseSettings):
model_config = SettingsConfigDict(populate_by_name=True)


@pytest.fixture(autouse=True)
def clean_env():
with mock.patch.dict(os.environ, clear=True):
yield


def test_sub_env(env):
env.set('apple', 'hello')
s = SimpleSettings()
Expand Down

0 comments on commit 00d1aac

Please sign in to comment.