mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix(test): add cleanup to prevent test pollution in CLI JWT expiration tests
The custom expiration test was setting LITELLM_CLI_JWT_EXPIRATION_HOURS=48 and reloading modules, but not cleaning up afterwards. This caused subsequent tests to use the cached 48-hour value instead of the default 24 hours. Added request.addfinalizer() to properly reload modules after the test completes, ensuring test isolation.
This commit is contained in:
parent
150363be0b
commit
4a0d63d063
1 changed files with 11 additions and 5 deletions
|
|
@ -156,17 +156,23 @@ def test_get_cli_jwt_auth_token_default_expiration(valid_sso_user_defined_values
|
|||
|
||||
|
||||
def test_get_cli_jwt_auth_token_custom_expiration(
|
||||
valid_sso_user_defined_values, monkeypatch
|
||||
valid_sso_user_defined_values, monkeypatch, request
|
||||
):
|
||||
"""Test generating CLI JWT token with custom expiration via environment variable"""
|
||||
import importlib
|
||||
from litellm import constants
|
||||
from litellm.proxy.auth import auth_checks
|
||||
|
||||
# Register cleanup to reload modules after test (monkeypatch restores env var automatically)
|
||||
def cleanup_modules():
|
||||
importlib.reload(constants)
|
||||
importlib.reload(auth_checks)
|
||||
request.addfinalizer(cleanup_modules)
|
||||
|
||||
# Set custom expiration to 48 hours
|
||||
monkeypatch.setenv("LITELLM_CLI_JWT_EXPIRATION_HOURS", "48")
|
||||
|
||||
# Reload the constants module to pick up the new env var
|
||||
import importlib
|
||||
|
||||
from litellm import constants
|
||||
from litellm.proxy.auth import auth_checks
|
||||
importlib.reload(constants)
|
||||
# Also reload auth_checks to pick up the new constant value
|
||||
importlib.reload(auth_checks)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue