Fix: Integrationstests isolieren (zerstörten die echte Datenbank)
Die Integrationstests mutierten das Modul-'app' und setzten erst in setUp
die :memory:-URI. Die Engine war zu dem Zeitpunkt aber längst an die
echte instance/typewriter.db gebunden, sodass db.create_all()/drop_all()
gegen die echte Datei liefen -> tearDown löschte bei JEDEM Testlauf alle
Tabellen der produktiven DB (Ursache der wiederkehrenden "FEHLENDE
TABELLEN"-Fehler).
Fix: setUp nutzt jetzt create_app({TESTING, :memory:, ...}) – eine
isolierte App mit eigener Engine (wie test_routes.py). Die echte DB wird
nicht mehr berührt; die Suite läuft zudem ~5x schneller (echte In-Memory
statt Datei-I/O).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0f45b7f73c
commit
454b5849a9
2 changed files with 18 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ import unittest
|
|||
import os
|
||||
os.environ['FLASK_TESTING'] = 'true' # Set before importing app
|
||||
|
||||
from app import app, db
|
||||
from app import create_app, db
|
||||
from models import Progress, LessonProgress
|
||||
from services.progress_service import ProgressService
|
||||
|
||||
|
|
@ -15,10 +15,11 @@ class TestProgressServiceIntegration(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Setup: Test-App und In-Memory-Datenbank"""
|
||||
app.config['TESTING'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
app.config['WTF_CSRF_ENABLED'] = False
|
||||
self.app = app
|
||||
self.app = create_app({
|
||||
'TESTING': True,
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
|
||||
'WTF_CSRF_ENABLED': False,
|
||||
})
|
||||
self.app_context = self.app.app_context()
|
||||
self.app_context.push()
|
||||
db.create_all()
|
||||
|
|
@ -259,10 +260,12 @@ class TestResolveCurrentLessonIndex(unittest.TestCase):
|
|||
"""Tests für die zentrale Lektions-Auflösung (Resume + Validierung)."""
|
||||
|
||||
def setUp(self):
|
||||
app.config['TESTING'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
app.config['WTF_CSRF_ENABLED'] = False
|
||||
self.app_context = app.app_context()
|
||||
self.app = create_app({
|
||||
'TESTING': True,
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
|
||||
'WTF_CSRF_ENABLED': False,
|
||||
})
|
||||
self.app_context = self.app.app_context()
|
||||
self.app_context.push()
|
||||
db.create_all()
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import os
|
|||
os.environ['FLASK_TESTING'] = 'true' # Set before importing app
|
||||
|
||||
from datetime import timedelta, date
|
||||
from app import app, db
|
||||
from app import create_app, db
|
||||
from models import LessonStatistic, DailyPractice
|
||||
from services.statistics_service import StatisticsService
|
||||
|
||||
|
|
@ -16,10 +16,11 @@ class TestStatisticsServiceIntegration(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Setup: Test-App und In-Memory-Datenbank"""
|
||||
app.config['TESTING'] = True
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
|
||||
app.config['WTF_CSRF_ENABLED'] = False
|
||||
self.app = app
|
||||
self.app = create_app({
|
||||
'TESTING': True,
|
||||
'SQLALCHEMY_DATABASE_URI': 'sqlite:///:memory:',
|
||||
'WTF_CSRF_ENABLED': False,
|
||||
})
|
||||
self.app_context = self.app.app_context()
|
||||
self.app_context.push()
|
||||
db.create_all()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue