Jeremiah Lowin commited on
Commit
f0a0f92
·
1 Parent(s): 927e044

Add env var test

Browse files
tests/deprecated/test_server_init_kwargs.py CHANGED
@@ -1,9 +1,11 @@
 
1
  import warnings
2
  from unittest.mock import patch
3
 
4
  import pytest
5
 
6
  from fastmcp import FastMCP
 
7
 
8
  # reset deprecation warnings for this module
9
  pytestmark = pytest.mark.filterwarnings("default::DeprecationWarning")
@@ -303,3 +305,31 @@ class TestDeprecatedServerInitKwargs:
303
  # This verifies the stacklevel is working as intended (pointing to constructor)
304
  warning = deprecation_warnings[0]
305
  assert "server.py" in warning.filename
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
  import warnings
3
  from unittest.mock import patch
4
 
5
  import pytest
6
 
7
  from fastmcp import FastMCP
8
+ from fastmcp.settings import Settings
9
 
10
  # reset deprecation warnings for this module
11
  pytestmark = pytest.mark.filterwarnings("default::DeprecationWarning")
 
305
  # This verifies the stacklevel is working as intended (pointing to constructor)
306
  warning = deprecation_warnings[0]
307
  assert "server.py" in warning.filename
308
+
309
+
310
+ class TestDeprecatedEnvironmentVariables:
311
+ """Test deprecated environment variable prefixes."""
312
+
313
+ def test_fastmcp_server_env_var_deprecation_warning(self):
314
+ """Test that FASTMCP_SERVER_ environment variables emit deprecation warnings."""
315
+ env_var_name = "FASTMCP_SERVER_HOST"
316
+ original_value = os.environ.get(env_var_name)
317
+
318
+ try:
319
+ os.environ[env_var_name] = "192.168.1.1"
320
+
321
+ with pytest.warns(
322
+ DeprecationWarning,
323
+ match=r"Using `FASTMCP_SERVER_` environment variables is deprecated\. Use `FASTMCP_` instead\.",
324
+ ):
325
+ settings = Settings()
326
+
327
+ # Verify the setting is still applied
328
+ assert settings.host == "192.168.1.1"
329
+
330
+ finally:
331
+ # Clean up environment variable
332
+ if original_value is not None:
333
+ os.environ[env_var_name] = original_value
334
+ else:
335
+ os.environ.pop(env_var_name, None)