-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Hi,
Im trying to get my test suite to run using an in memory sqlite db, as its very slow using one on the file system, but im finding failures, and not sure if i have things setup properly, or if there is an issue with the persistence of the connection, heres an excerpt from my setup:
# conftest.py
from typing import Any, AsyncGenerator
import pytest
from pydbantic import Database
from myapp.models import MyModel
@pytest.fixture
async def setup_db() -> AsyncGenerator[Database, Any]:
db_url = "sqlite:///:memory:"
db = await Database.create(
db_url,
tables=[MyModel],
cache_enabled=False,
testing=True,
)
yield db
db.metadata.drop_all(db.engine)
async def test_thing(setup_db: Database) -> None:
shop = await MyModel.create(name="test")
assert shop is not None
And i seem to get ERROR tests/test_thing.py::test_thing - sqlite3.OperationalError: no such table: DatabaseInit
Which looks like the database session is not being reused, ive tried various things like sqlite:///:memory:?cache=shared to no avail.
Do you see anything immediately wrong in my approach ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels