@@ -15,22 +15,20 @@ class TestSettings:
1515
1616 def test_settings_loads_from_env (self ) -> None :
1717 """Settings should load API key from environment variable."""
18- with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-test-key" }):
19- settings = Settings ()
18+ with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-test-key" }, clear = True ):
19+ settings = Settings (_env_file = None )
2020 assert settings .openai_api_key .get_secret_value () == "sk-test-key"
2121
2222 def test_settings_requires_api_key (self ) -> None :
2323 """Settings should raise error when API key is missing."""
2424 with patch .dict (os .environ , {}, clear = True ):
25- # Remove any existing OPENAI_API_KEY
26- os .environ .pop ("OPENAI_API_KEY" , None )
2725 with pytest .raises (ValidationError ):
28- Settings ()
26+ Settings (_env_file = None )
2927
3028 def test_settings_default_values (self ) -> None :
3129 """Settings should have correct default values."""
32- with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-test" }):
33- settings = Settings ()
30+ with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-test" }, clear = True ):
31+ settings = Settings (_env_file = None )
3432 assert settings .output_format == "txt"
3533 assert settings .concurrency == 5
3634 assert settings .language == "auto"
@@ -42,31 +40,35 @@ def test_settings_concurrency_validation_min(self) -> None:
4240 with patch .dict (
4341 os .environ ,
4442 {"OPENAI_API_KEY" : "sk-test" , "TRANSCRIBE_CONCURRENCY" : "0" },
43+ clear = True ,
4544 ):
4645 with pytest .raises (ValidationError ) as exc_info :
47- Settings ()
46+ Settings (_env_file = None )
4847 assert "at least 1" in str (exc_info .value )
4948
5049 def test_settings_concurrency_validation_max (self ) -> None :
5150 """Concurrency should not exceed 20."""
5251 with patch .dict (
5352 os .environ ,
5453 {"OPENAI_API_KEY" : "sk-test" , "TRANSCRIBE_CONCURRENCY" : "25" },
54+ clear = True ,
5555 ):
5656 with pytest .raises (ValidationError ) as exc_info :
57- Settings ()
57+ Settings (_env_file = None )
5858 assert "cannot exceed 20" in str (exc_info .value )
5959
6060 def test_settings_output_dir_resolved (self ) -> None :
6161 """Output directory should be resolved to absolute path."""
62- with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-test" }):
63- settings = Settings (output_dir = Path ("." ))
62+ with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-test" }, clear = True ):
63+ settings = Settings (_env_file = None , output_dir = Path ("." ))
6464 assert settings .output_dir .is_absolute ()
6565
6666 def test_settings_api_key_not_in_repr (self ) -> None :
6767 """API key should not appear in string representation (security)."""
68- with patch .dict (os .environ , {"OPENAI_API_KEY" : "sk-secret-key-12345" }):
69- settings = Settings ()
68+ with patch .dict (
69+ os .environ , {"OPENAI_API_KEY" : "sk-secret-key-12345" }, clear = True
70+ ):
71+ settings = Settings (_env_file = None )
7072 repr_str = repr (settings )
7173 assert "sk-secret-key-12345" not in repr_str
7274 assert "SecretStr" in repr_str or "**" in repr_str
0 commit comments