Testing#
Quart-DB uses the Quart startup functionality to connect to the database and create the connection pool. Therefore the test_app will need to be used to ensure that the connection is setup for testing as well, see the docs. To do so I recommend the following fixture be used with pytest,
@pytest.fixture(name="app", scope="function")
async def _app():
app = create_app() # Initialize app
async with app.test_app() as test_app:
yield test_app
If you would like only a connection for usage in tests I recommend the
following fixture note the DATABASE_URL
is being supplied as a
environment variable,
@pytest.fixture(name="connection")
async def _connection():
db = QuartDB(Quart(__name__), url=os.environ["DATABASE_URL"])
connection = Connection(asyncpg_connection)
async with db.connection() as connection:
yield connection