Skip to content

Commit 00d1aac

Browse files
committed
Strip environment for test_settings
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
1 parent 91ed1c2 commit 00d1aac

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tests/test_settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from enum import IntEnum
88
from pathlib import Path
99
from typing import Any, Callable, Dict, Generic, Hashable, List, Optional, Set, Tuple, Type, TypeVar, Union
10+
from unittest import mock
1011

1112
import pytest
1213
from annotated_types import MinLen
@@ -68,6 +69,12 @@ class SettingWithPopulateByName(BaseSettings):
6869
model_config = SettingsConfigDict(populate_by_name=True)
6970

7071

72+
@pytest.fixture(autouse=True)
73+
def clean_env():
74+
with mock.patch.dict(os.environ, clear=True):
75+
yield
76+
77+
7178
def test_sub_env(env):
7279
env.set('apple', 'hello')
7380
s = SimpleSettings()

0 commit comments

Comments
 (0)