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:
Alexsander Hamir 2026-01-27 12:39:05 -08:00
parent 150363be0b
commit 4a0d63d063

View file

@ -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)