mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-20 00:11:50 +00:00
fix(test): use autouse fixture to ensure module cleanup across all tests
Added autouse fixture that reloads constants and auth_checks modules before and after each test. This ensures complete test isolation and prevents any test from polluting module state for subsequent tests, regardless of test execution order.
This commit is contained in:
parent
173652ab19
commit
33470fe269
1 changed files with 19 additions and 7 deletions
|
|
@ -44,6 +44,24 @@ def set_salt_key(monkeypatch):
|
|||
monkeypatch.setenv("LITELLM_SALT_KEY", "sk-1234")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_constants_module():
|
||||
"""Reset constants module to ensure clean state before each test"""
|
||||
import importlib
|
||||
from litellm import constants
|
||||
from litellm.proxy.auth import auth_checks
|
||||
|
||||
# Reload modules before test
|
||||
importlib.reload(constants)
|
||||
importlib.reload(auth_checks)
|
||||
|
||||
yield
|
||||
|
||||
# Reload modules after test to clean up
|
||||
importlib.reload(constants)
|
||||
importlib.reload(auth_checks)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def valid_sso_user_defined_values():
|
||||
return LiteLLM_UserTable(
|
||||
|
|
@ -156,19 +174,13 @@ 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, request
|
||||
valid_sso_user_defined_values, monkeypatch
|
||||
):
|
||||
"""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")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue