You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ?
The text was updated successfully, but these errors were encountered:
Hi @farridav I had a look at what is causing it, looks like its a known issue from encode/databases#75 - the library partly responsible for connections in pydbantic. I would suggest the workaround of using a file DB perhaps in a temporary location such as /tmp/ which should be much faster than disk.
Thanks for looking into this for me, its a shame.. I'm trying to switch over from sqlmodel to pydbantic, to do away with all the sqlalchemy connection handling and boilerplate, here are the timings between the two implementations:
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:
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 ?
The text was updated successfully, but these errors were encountered: