Skip to content

Commit

Permalink
configure setup and teardown process for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imryche committed Jun 30, 2024
1 parent ad67278 commit 6fdd353
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tests/test_litequery.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import os
import pytest
import aiosqlite
import litequery
import pytest_asyncio

DATABASE_PATH = "test.db"
QUERIES_PATH = "queries.sql"

@pytest.mark.asyncio
async def test_queries():
lq = litequery.create("users.db", "queries.sql")

@pytest_asyncio.fixture
async def setup_database():
async with aiosqlite.connect(DATABASE_PATH) as conn:
await conn.execute(
"create table users (id integer primary key autoincrement, name text)"
)
await conn.commit()
yield
os.remove(DATABASE_PATH)


@pytest_asyncio.fixture
async def lq(setup_database):
lq = litequery.create(DATABASE_PATH, QUERIES_PATH)
await lq.connect()
yield lq
await lq.disconnect()


@pytest.mark.asyncio
async def test_queries(lq):
print(await lq.users_delete_all())
print(await lq.users_insert(name="kocia"))
print(await lq.users_insert(name="kot"))
print(await lq.users_insert(name="simba"))
print(await lq.users_insert(name="bunchik"))
print(await lq.users_all())
print(await lq.users_first())
await lq.disconnect()
Binary file removed users.db
Binary file not shown.

0 comments on commit 6fdd353

Please sign in to comment.