Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Merged
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_packages(package):
packages=get_packages(PACKAGE),
package_data={PACKAGE: ["py.typed"]},
data_files=[("", ["LICENSE.md"])],
install_requires=["databases>=0.2.1", "typesystem"],
install_requires=["anyio>=3.0.0,<4", "databases>=0.2.1", "typesystem"],
extras_require={
"postgresql": ["asyncpg"],
"mysql": ["aiomysql"],
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture
def anyio_backend():
return ("asyncio", {"debug": True})
3 changes: 2 additions & 1 deletion tests/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import orm
from tests.settings import DATABASE_URL

pytestmark = pytest.mark.anyio

database = databases.Database(DATABASE_URL, force_rollback=True)
metadata = sqlalchemy.MetaData()

Expand Down Expand Up @@ -45,7 +47,6 @@ def create_test_database():
metadata.drop_all(engine)


@pytest.mark.asyncio
async def test_model_crud():
async with database:
await Example.objects.create()
Expand Down
6 changes: 2 additions & 4 deletions tests/test_foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import orm
from tests.settings import DATABASE_URL

pytestmark = pytest.mark.anyio

database = databases.Database(DATABASE_URL, force_rollback=True)
metadata = sqlalchemy.MetaData()

Expand Down Expand Up @@ -66,7 +68,6 @@ def create_test_database():
metadata.drop_all(engine)


@pytest.mark.asyncio
async def test_model_crud():
async with database:
album = await Album.objects.create(name="Malibu")
Expand All @@ -83,7 +84,6 @@ async def test_model_crud():
assert track.album.name == "Malibu"


@pytest.mark.asyncio
async def test_select_related():
async with database:
album = await Album.objects.create(name="Malibu")
Expand All @@ -105,7 +105,6 @@ async def test_select_related():
assert len(tracks) == 6


@pytest.mark.asyncio
async def test_fk_filter():
async with database:
malibu = await Album.objects.create(name="Malibu")
Expand Down Expand Up @@ -149,7 +148,6 @@ async def test_fk_filter():
assert track.album.name == "Malibu"


@pytest.mark.asyncio
async def test_multiple_fk():
async with database:
acme = await Organisation.objects.create(ident="ACME Ltd")
Expand Down
14 changes: 2 additions & 12 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import orm
from tests.settings import DATABASE_URL

pytestmark = pytest.mark.anyio

database = databases.Database(DATABASE_URL, force_rollback=True)
metadata = sqlalchemy.MetaData()

Expand Down Expand Up @@ -52,7 +54,6 @@ def test_model_pk():
assert user.id == 1


@pytest.mark.asyncio
async def test_model_crud():
async with database:
users = await User.objects.all()
Expand All @@ -78,7 +79,6 @@ async def test_model_crud():
assert users == []


@pytest.mark.asyncio
async def test_model_get():
async with database:
with pytest.raises(orm.NoMatch):
Expand All @@ -97,7 +97,6 @@ async def test_model_get():
assert same_user.pk == user.pk


@pytest.mark.asyncio
async def test_model_filter():
async with database:
await User.objects.create(name="Tom")
Expand Down Expand Up @@ -157,7 +156,6 @@ async def test_model_filter():
assert await products.count() == 3


@pytest.mark.asyncio
async def test_model_order_by():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -170,7 +168,6 @@ async def test_model_order_by():
assert users[2].name == "Tom"


@pytest.mark.asyncio
async def test_model_order_by_desc():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -183,7 +180,6 @@ async def test_model_order_by_desc():
assert users[2].name == "Allen"


@pytest.mark.asyncio
async def test_model_order_by_multi():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -197,15 +193,13 @@ async def test_model_order_by_multi():
assert users[1].id == 2


@pytest.mark.asyncio
async def test_model_exists():
async with database:
await User.objects.create(name="Tom")
assert await User.objects.filter(name="Tom").exists() is True
assert await User.objects.filter(name="Jane").exists() is False


@pytest.mark.asyncio
async def test_model_count():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -216,7 +210,6 @@ async def test_model_count():
assert await User.objects.filter(name__icontains="T").count() == 1


@pytest.mark.asyncio
async def test_model_limit():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -226,7 +219,6 @@ async def test_model_limit():
assert len(await User.objects.limit(2).all()) == 2


@pytest.mark.asyncio
async def test_model_limit_with_filter():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -236,7 +228,6 @@ async def test_model_limit_with_filter():
assert len(await User.objects.limit(2).filter(name__iexact="Tom").all()) == 2


@pytest.mark.asyncio
async def test_offset():
async with database:
await User.objects.create(name="Tom")
Expand All @@ -246,7 +237,6 @@ async def test_offset():
assert users[0].name == "Jane"


@pytest.mark.asyncio
async def test_model_first():
async with database:
tom = await User.objects.create(name="Tom")
Expand Down