fix(tests): resolve CI test failures from asyncio event loop and settings reload side-effects
Two root causes identified and fixed: 1. tests/test_api_settings.py (TestListCredentials): asyncio.get_event_loop().run_until_complete() raised RuntimeError in Python 3.12 because test_api_auth_enabled.py's asyncio.run() sets the current event loop to None on completion. Replace all 7 occurrences with asyncio.run() which creates its own event loop each time. 2. tests/test_cors.py: reload(app.config) replaced the app.config.settings singleton with a new instance, so app modules holding the original reference no longer saw patches applied to app.config.settings.X. This caused the notification, OpenAI, and file-upload tests to behave as if unpatched. Remove the redundant reload() calls — the tests only need a fresh Settings(...) instance constructed with the env var already set. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
+4
-10
@@ -169,12 +169,9 @@ def test_cors_parse_comma_separated_origins():
|
||||
original = os.environ.get("CORS_ALLOWED_ORIGINS")
|
||||
os.environ["CORS_ALLOWED_ORIGINS"] = "https://app.example.com,https://admin.example.com"
|
||||
try:
|
||||
from importlib import reload
|
||||
from app.config import Settings
|
||||
|
||||
import app.config as config_module
|
||||
|
||||
reload(config_module)
|
||||
test_settings = config_module.Settings(
|
||||
test_settings = Settings(
|
||||
database_url="sqlite:///:memory:",
|
||||
redis_url="redis://localhost:6379/0",
|
||||
openai_api_key="test-key",
|
||||
@@ -204,12 +201,9 @@ def test_cors_single_origin_string_to_list():
|
||||
original = os.environ.get("CORS_ALLOWED_ORIGINS")
|
||||
os.environ["CORS_ALLOWED_ORIGINS"] = "https://app.example.com"
|
||||
try:
|
||||
from importlib import reload
|
||||
from app.config import Settings
|
||||
|
||||
import app.config as config_module
|
||||
|
||||
reload(config_module)
|
||||
test_settings = config_module.Settings(
|
||||
test_settings = Settings(
|
||||
database_url="sqlite:///:memory:",
|
||||
redis_url="redis://localhost:6379/0",
|
||||
openai_api_key="test-key",
|
||||
|
||||
Reference in New Issue
Block a user