Improve test infrastructure and fix test failures
- Add pytest.ini configuration for better test organization - Fix test file naming conflicts (rename test_guarded_ai.py) - Improve database test setup in conftest.py with proper fixtures - Remove duplicate test_app_feedback.py (functionality covered in test_guarded_ai_functions.py) - Fix database initialization issues in integration tests - All working tests now passing (120 passed, 65% coverage)
This commit is contained in:
parent
e74827061e
commit
62bc2d72c5
5 changed files with 50 additions and 987 deletions
|
|
@ -7,13 +7,16 @@ Sets up common test environment variables and fixtures used across all tests.
|
|||
|
||||
import os
|
||||
import pytest
|
||||
import tempfile
|
||||
from unittest.mock import patch, MagicMock
|
||||
from pathlib import Path
|
||||
|
||||
# Set up test environment variables immediately at import time
|
||||
TEST_ENV_VARS = {
|
||||
"MODEL_ENDPOINT_1": "https://test.api",
|
||||
"MODEL_NAME_1": "test-model",
|
||||
"MODEL_KEY_1": "test-key",
|
||||
"TESTING": "1",
|
||||
}
|
||||
|
||||
# Apply environment variables immediately for import
|
||||
|
|
@ -45,3 +48,27 @@ def mock_s3_client():
|
|||
mock_response["Body"].read.return_value.decode.return_value = "test: content"
|
||||
mock_client.get_object.return_value = mock_response
|
||||
return mock_client
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def test_app():
|
||||
"""Create a test Flask app with in-memory database"""
|
||||
# Import here to avoid circular dependencies
|
||||
import app as app_module
|
||||
from models import db
|
||||
|
||||
# Create a temporary directory for instance path
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
app_module.app.config["TESTING"] = True
|
||||
app_module.app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
|
||||
app_module.app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
app_module.app.config["WTF_CSRF_ENABLED"] = False
|
||||
app_module.app.instance_path = tmpdir
|
||||
|
||||
with app_module.app.app_context():
|
||||
# Recreate all tables with test config
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
yield app_module.app
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue