From 67259d689bdcaa0f10d3ac535fff93fe914b906b Mon Sep 17 00:00:00 2001 From: eclipse Date: Sat, 26 Jul 2025 18:35:17 +0200 Subject: [PATCH] ficture _db now comes with a prepopulated Genre table, and _app has an app_context right away --- tests/conftest.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 4648ef0..e25f530 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ import pytest from the_works import create_app from the_works.database import db as _db +from the_works.models import Genre TEST_DATABASE_URI = "sqlite:///:memory:" @@ -15,15 +16,21 @@ def _app(): _app = create_app(test_config) # other setup can go here + context = _app.app_context() + context.push() yield _app # clean up / reset resources here + context.pop() @pytest.fixture(scope="function") def db(_app): with _app.app_context(): + _db.session.add(Genre(ID=1, Genre="spam")) + _db.session.add(Genre(ID=2, Genre="eggs")) + _db.session.commit() yield _db _db.drop_all() _db.create_all()