1111
1212@pytest .fixture
1313def env_file (tmp_path : Path ) -> Path :
14- """Create a temporary .env file with a test variable ."""
14+ """Create a temporary .env file."""
1515 p = tmp_path / ".env"
1616 p .write_text ("MY_TEST_VAR=from_dotenv\n " )
1717 return p
@@ -32,30 +32,23 @@ def test_returns_path_when_env_var_is_set(env_file: Path) -> None:
3232 assert result == str (env_file )
3333
3434
35- def test_loads_dotenv_when_path_is_set ( env_file : Path ) -> None :
36- """When a path is returned, load_dotenv should populate os.environ ."""
35+ def test_respects_env_prefix ( ) -> None :
36+ """Only the env var with the correct prefix is read ."""
3737 with patch .dict (
3838 os .environ ,
39- {"OT_TEST_SERVER_dot_env_path " : str ( env_file ) },
39+ {"OT_OTHER_SERVER_dot_env_path " : "/some/path" },
4040 clear = False ,
4141 ):
42- get_dot_env_path ("OT_TEST_SERVER_" )
43- assert os .environ .get ("MY_TEST_VAR" ) == "from_dotenv"
44-
45-
46- def test_does_not_load_dotenv_when_no_path () -> None :
47- """When no path is set, load_dotenv should not be called."""
48- with patch ("server_utils.settings_utils.load_dotenv" ) as mock_load :
49- get_dot_env_path ("OT_NONEXISTENT_PREFIX_" )
50- mock_load .assert_not_called ()
42+ result = get_dot_env_path ("OT_MY_SERVER_" )
43+ assert result is None
5144
5245
53- def test_respects_env_prefix ( ) -> None :
54- """Only the env var with the correct prefix is read ."""
46+ def test_does_not_modify_os_environ ( env_file : Path ) -> None :
47+ """The function should not call load_dotenv or modify os.environ ."""
5548 with patch .dict (
5649 os .environ ,
57- {"OT_OTHER_SERVER_dot_env_path " : "/some/path" },
50+ {"OT_TEST_SERVER_dot_env_path " : str ( env_file ) },
5851 clear = False ,
5952 ):
60- result = get_dot_env_path ("OT_MY_SERVER_ " )
61- assert result is None
53+ get_dot_env_path ("OT_TEST_SERVER_ " )
54+ assert "MY_TEST_VAR" not in os . environ
0 commit comments