Skip to content

Commit

Permalink
update test for missing .env file behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
rambo committed Feb 6, 2024
1 parent 73b13bb commit dc2b914
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import typing
import warnings
from pathlib import Path
from typing import Any, Optional

Expand Down Expand Up @@ -105,11 +106,15 @@ def cast_to_int(v: typing.Any) -> int:
config.get("BOOL_AS_INT", cast=bool)


def test_missing_env_file_raises(tmpdir: Path) -> None:
def test_missing_env_file_warns_only_if_requested(tmpdir: Path) -> None:
path = os.path.join(tmpdir, ".env")

with pytest.raises(FileNotFoundError, match=f"Config file '{path}' not found."):
with warnings.catch_warnings(record=True) as caught:
Config(path)
assert not caught
with pytest.raises(UserWarning):
Config(path, warn_missing=True)
assert caught


def test_environ() -> None:
Expand Down

0 comments on commit dc2b914

Please sign in to comment.