55from app .core .config import get_env_file
66
77
8+ @pytest .fixture (autouse = True )
9+ def disable_ci (monkeypatch ):
10+ """
11+ Ensure tests exercise *local development* behavior.
12+
13+ In CI, we intentionally set `CI=true`, which causes `get_env_file()`
14+ to return None and rely solely on environment variables.
15+
16+ This test suite validates the *file-based* behavior used in local
17+ development (i.e., resolving `.envs/<APP_ENV>/backend.env`), so we
18+ explicitly unset `CI` here to avoid CI-specific code paths.
19+ """
20+ monkeypatch .delenv ("CI" , raising = False )
21+
22+
823class TestGetEnvFile :
924 @pytest .fixture (autouse = True )
1025 def restore_env (self , monkeypatch ):
@@ -37,7 +52,7 @@ def test_returns_dev_env_file_by_default(self, tmp_path, monkeypatch):
3752 (root / ".envs/dev/backend.env" ).write_text ("OK" )
3853 env_file = get_env_file (project_root = root )
3954
40- assert env_file .endswith ("dev/backend.env" )
55+ assert env_file .endswith ("dev/backend.env" ) # type: ignore[union-attr]
4156
4257 def test_returns_dev_env_file_when_app_env_is_dev (self , tmp_path , monkeypatch ):
4358 monkeypatch .setenv ("APP_ENV" , "dev" )
@@ -46,7 +61,7 @@ def test_returns_dev_env_file_when_app_env_is_dev(self, tmp_path, monkeypatch):
4661 (root / ".envs/dev/backend.env" ).write_text ("OK" )
4762 env_file = get_env_file (project_root = root )
4863
49- assert env_file .endswith ("dev/backend.env" )
64+ assert env_file .endswith ("dev/backend.env" ) # type: ignore[union-attr]
5065
5166 def test_returns_dev_docker_env_file_when_app_env_is_dev_docker (
5267 self , tmp_path , monkeypatch
@@ -55,9 +70,9 @@ def test_returns_dev_docker_env_file_when_app_env_is_dev_docker(
5570 root = tmp_path
5671 (root / ".envs/dev_docker" ).mkdir (parents = True )
5772 (root / ".envs/dev_docker/backend.env" ).write_text ("OK" )
58- env_file = get_env_file (project_root = root )
5973
60- assert env_file .endswith ("dev_docker/backend.env" )
74+ env_file = get_env_file (project_root = root )
75+ assert env_file .endswith ("dev_docker/backend.env" ) # type: ignore[union-attr]
6176
6277 def test_returns_prod_env_file_when_app_env_is_prod (self , tmp_path , monkeypatch ):
6378 monkeypatch .setenv ("APP_ENV" , "prod" )
@@ -66,7 +81,7 @@ def test_returns_prod_env_file_when_app_env_is_prod(self, tmp_path, monkeypatch)
6681 (root / ".envs/prod/backend.env" ).write_text ("OK" )
6782
6883 env_file = get_env_file (project_root = root )
69- assert env_file .endswith ("prod/backend.env" )
84+ assert env_file .endswith ("prod/backend.env" ) # type: ignore[union-attr]
7085
7186 def test_raises_when_only_example_env_file_exists (self , tmp_path , monkeypatch ):
7287 monkeypatch .setenv ("APP_ENV" , "dev" )
@@ -84,16 +99,9 @@ def test_raises_when_env_file_does_not_exist(self, tmp_path, monkeypatch):
8499 with pytest .raises (FileNotFoundError ):
85100 get_env_file (project_root = root )
86101
87- def test_raises_when_env_file_is_missing_and_only_example_exists (
88- self , tmp_path , monkeypatch
89- ):
90- monkeypatch .setenv ("APP_ENV" , "dev" )
102+ def test_returns_none_if_environment_is_ci (self , tmp_path , monkeypatch ):
103+ monkeypatch .setenv ("CI" , "true" )
91104 root = tmp_path
92- (root / ".envs/dev" ).mkdir (parents = True )
93- (root / ".envs/dev/backend.env.example" ).write_text ("# example" )
94- env_file = root / ".envs/dev/backend.env"
105+ env_file = get_env_file (project_root = root )
95106
96- if env_file .exists ():
97- env_file .unlink ()
98- with pytest .raises (FileNotFoundError ):
99- get_env_file (project_root = root )
107+ assert env_file is None
0 commit comments