Skip to content

Commit 0de9e20

Browse files
committed
fix fixtures async
1 parent ba8c368 commit 0de9e20

File tree

6 files changed

+36
-41
lines changed

6 files changed

+36
-41
lines changed

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from fastapi import FastAPI
66
from httpx import AsyncClient
7-
from pytest_asyncio import fixture as async_fixture, is_async_test
7+
from pytest_asyncio import is_async_test
88

99
from tests.fixtures.app import ( # noqa
1010
app,
@@ -75,7 +75,7 @@ def pytest_collection_modifyitems(items):
7575
async_test.add_marker(session_scope_marker, append=False)
7676

7777

78-
@async_fixture()
78+
@pytest.fixture()
7979
async def client(app: FastAPI) -> AsyncClient: # noqa: F811
8080
async with AsyncClient(app=app, base_url="http://test") as ac:
8181
yield ac

tests/fixtures/entities.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import TYPE_CHECKING, Callable
44

55
import pytest
6-
from pytest_asyncio import fixture as async_fixture
76

87
from tests.misc.utils import fake
98
from tests.models import (
@@ -41,7 +40,7 @@ async def create_user(async_session: AsyncSession, **fields):
4140
return user
4241

4342

44-
@async_fixture()
43+
@pytest.fixture()
4544
async def user_1(async_session: AsyncSession):
4645
user = build_user()
4746
async_session.add(user)
@@ -52,7 +51,7 @@ async def user_1(async_session: AsyncSession):
5251
await async_session.commit()
5352

5453

55-
@async_fixture()
54+
@pytest.fixture()
5655
async def user_2(async_session: AsyncSession):
5756
user = build_user()
5857
async_session.add(user)
@@ -63,7 +62,7 @@ async def user_2(async_session: AsyncSession):
6362
await async_session.commit()
6463

6564

66-
@async_fixture()
65+
@pytest.fixture()
6766
async def user_3(async_session: AsyncSession):
6867
user = build_user()
6968
async_session.add(user)
@@ -81,7 +80,7 @@ async def build_user_bio(async_session: AsyncSession, user: User, **fields):
8180
return bio
8281

8382

84-
@async_fixture()
83+
@pytest.fixture()
8584
async def user_1_bio(async_session: AsyncSession, user_1: User) -> UserBio:
8685
return await build_user_bio(
8786
async_session,
@@ -92,7 +91,7 @@ async def user_1_bio(async_session: AsyncSession, user_1: User) -> UserBio:
9291
)
9392

9493

95-
@async_fixture()
94+
@pytest.fixture()
9695
async def user_2_bio(async_session: AsyncSession, user_2: User) -> UserBio:
9796
return await build_user_bio(
9897
async_session,
@@ -111,7 +110,7 @@ async def build_post(async_session: AsyncSession, user: User, **fields) -> Post:
111110
return post
112111

113112

114-
@async_fixture()
113+
@pytest.fixture()
115114
async def user_1_posts(async_session: AsyncSession, user_1: User) -> list[Post]:
116115
posts = [
117116
Post(
@@ -130,7 +129,7 @@ async def user_1_posts(async_session: AsyncSession, user_1: User) -> list[Post]:
130129
return posts
131130

132131

133-
@async_fixture()
132+
@pytest.fixture()
134133
async def user_1_post(async_session: AsyncSession, user_1: User):
135134
post = Post(title="post_for_u1", user=user_1)
136135
async_session.add(post)
@@ -144,7 +143,7 @@ async def user_1_post(async_session: AsyncSession, user_1: User):
144143
await async_session.commit()
145144

146145

147-
@async_fixture()
146+
@pytest.fixture()
148147
async def user_2_posts(async_session: AsyncSession, user_2: User) -> list[Post]:
149148
posts = [
150149
Post(
@@ -163,7 +162,7 @@ async def user_2_posts(async_session: AsyncSession, user_2: User) -> list[Post]:
163162
return posts
164163

165164

166-
@async_fixture()
165+
@pytest.fixture()
167166
async def user_1_comments_for_u2_posts(async_session: AsyncSession, user_1, user_2_posts):
168167
post_comments = [
169168
PostComment(
@@ -191,7 +190,7 @@ def user_1_post_for_comments(user_1_posts: list[Post]) -> Post:
191190
return user_1_posts[0]
192191

193192

194-
@async_fixture()
193+
@pytest.fixture()
195194
async def computer_1(async_session: AsyncSession):
196195
computer = Computer(name="Halo")
197196

@@ -205,7 +204,7 @@ async def computer_1(async_session: AsyncSession):
205204
await async_session.commit()
206205

207206

208-
@async_fixture()
207+
@pytest.fixture()
209208
async def computer_2(async_session: AsyncSession):
210209
computer = Computer(name="Nestor")
211210

@@ -219,7 +218,7 @@ async def computer_2(async_session: AsyncSession):
219218
await async_session.commit()
220219

221220

222-
@async_fixture()
221+
@pytest.fixture()
223222
async def computer_factory(async_session: AsyncSession) -> Callable[[str | None], Awaitable[Computer]]:
224223
async def factory(name: str | None = None) -> Computer:
225224
computer = Computer(name=name or fake.word())
@@ -248,7 +247,7 @@ async def build_post_comment(
248247
return post_comment
249248

250249

251-
@async_fixture()
250+
@pytest.fixture()
252251
async def user_2_comment_for_one_u1_post(async_session: AsyncSession, user_2, user_1_post_for_comments):
253252
post = user_1_post_for_comments
254253
post_comment = PostComment(
@@ -267,7 +266,7 @@ async def user_2_comment_for_one_u1_post(async_session: AsyncSession, user_2, us
267266
await async_session.commit()
268267

269268

270-
@async_fixture()
269+
@pytest.fixture()
271270
async def parent_1(async_session: AsyncSession):
272271
parent = Parent(
273272
name="parent_1",
@@ -283,7 +282,7 @@ async def parent_1(async_session: AsyncSession):
283282
await async_session.commit()
284283

285284

286-
@async_fixture()
285+
@pytest.fixture()
287286
async def parent_2(async_session: AsyncSession):
288287
parent = Parent(
289288
name="parent_2",
@@ -299,7 +298,7 @@ async def parent_2(async_session: AsyncSession):
299298
await async_session.commit()
300299

301300

302-
@async_fixture()
301+
@pytest.fixture()
303302
async def parent_3(async_session: AsyncSession):
304303
parent = Parent(
305304
name="parent_3",
@@ -315,7 +314,7 @@ async def parent_3(async_session: AsyncSession):
315314
await async_session.commit()
316315

317316

318-
@async_fixture()
317+
@pytest.fixture()
319318
async def child_1(async_session: AsyncSession):
320319
child = Child(
321320
name="child_1",
@@ -331,7 +330,7 @@ async def child_1(async_session: AsyncSession):
331330
await async_session.commit()
332331

333332

334-
@async_fixture()
333+
@pytest.fixture()
335334
async def child_2(async_session: AsyncSession):
336335
child = Child(
337336
name="child_2",
@@ -347,7 +346,7 @@ async def child_2(async_session: AsyncSession):
347346
await async_session.commit()
348347

349348

350-
@async_fixture()
349+
@pytest.fixture()
351350
async def child_3(async_session: AsyncSession):
352351
child = Child(
353352
name="child_3",
@@ -363,7 +362,7 @@ async def child_3(async_session: AsyncSession):
363362
await async_session.commit()
364363

365364

366-
@async_fixture()
365+
@pytest.fixture()
367366
async def child_4(async_session: AsyncSession):
368367
child = Child(
369368
name="child_4",
@@ -379,7 +378,7 @@ async def child_4(async_session: AsyncSession):
379378
await async_session.commit()
380379

381380

382-
@async_fixture()
381+
@pytest.fixture()
383382
async def p1_c1_association(
384383
async_session: AsyncSession,
385384
parent_1: Parent,
@@ -401,7 +400,7 @@ async def p1_c1_association(
401400
await async_session.commit()
402401

403402

404-
@async_fixture()
403+
@pytest.fixture()
405404
async def p2_c1_association(
406405
async_session: AsyncSession,
407406
parent_2: Parent,
@@ -423,7 +422,7 @@ async def p2_c1_association(
423422
await async_session.commit()
424423

425424

426-
@async_fixture()
425+
@pytest.fixture()
427426
async def p1_c2_association(
428427
async_session: AsyncSession,
429428
parent_1: Parent,
@@ -445,7 +444,7 @@ async def p1_c2_association(
445444
await async_session.commit()
446445

447446

448-
@async_fixture()
447+
@pytest.fixture()
449448
async def p2_c2_association(
450449
async_session: AsyncSession,
451450
parent_2: Parent,
@@ -467,7 +466,7 @@ async def p2_c2_association(
467466
await async_session.commit()
468467

469468

470-
@async_fixture()
469+
@pytest.fixture()
471470
async def p2_c3_association(
472471
async_session: AsyncSession,
473472
parent_2: Parent,
@@ -498,14 +497,14 @@ async def build_workplace(async_session: AsyncSession, **fields):
498497
return workplace
499498

500499

501-
@async_fixture()
500+
@pytest.fixture()
502501
async def workplace_1(
503502
async_session: AsyncSession,
504503
):
505504
yield await build_workplace(async_session, name="workplace_1")
506505

507506

508-
@async_fixture()
507+
@pytest.fixture()
509508
async def workplace_2(
510509
async_session: AsyncSession,
511510
):

tests/test_api/test_custom_body_dependency.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44
from fastapi import Body, Depends, FastAPI, HTTPException, status
55
from httpx import AsyncClient
6-
from pytest_asyncio import fixture
76
from sqlalchemy.ext.asyncio import AsyncSession
87

98
from fastapi_jsonapi.misc.sqla.generics.base import DetailViewBaseGeneric, ListViewBaseGeneric
@@ -42,7 +41,7 @@ def app_w_deps(resource_type):
4241
)
4342

4443

45-
@fixture(scope="class")
44+
@pytest.fixture()
4645
async def client(app_w_deps: FastAPI):
4746
async with AsyncClient(app=app_w_deps, base_url="http://test") as client:
4847
yield client

tests/test_api/test_validators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
BaseModel as PydanticBaseModel,
2323
)
2424
from pydantic_core.core_schema import ValidationInfo
25-
from pytest_asyncio import fixture
2625

2726
from fastapi_jsonapi import RoutersJSONAPI
2827
from fastapi_jsonapi.schema import BaseModel
@@ -42,7 +41,7 @@
4241
from sqlalchemy.ext.asyncio import AsyncSession
4342

4443

45-
@fixture()
44+
@pytest.fixture()
4645
def refresh_caches() -> None:
4746
object_schemas_cache = deepcopy(SchemaBuilder.object_schemas_cache)
4847
relationship_schema_cache = deepcopy(SchemaBuilder.relationship_schema_cache)
@@ -59,7 +58,7 @@ def refresh_caches() -> None:
5958
RoutersJSONAPI.all_jsonapi_routers = all_jsonapi_routers
6059

6160

62-
@fixture()
61+
@pytest.fixture()
6362
async def task_with_none_ids(
6463
async_session: AsyncSession,
6564
) -> Task:

tests/test_atomic/test_current_atomic_operation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from fastapi import Body, Depends, FastAPI, HTTPException, status
77
from httpx import AsyncClient
88
from pydantic import BaseModel
9-
from pytest_asyncio import fixture
109

1110
from fastapi_jsonapi.atomic import current_atomic_operation
1211
from fastapi_jsonapi.misc.sqla.generics.base import DetailViewBaseGeneric, ListViewBaseGeneric
@@ -172,7 +171,7 @@ def app_w_deps(self, resource_type):
172171
path=f"/path_{resource_type}",
173172
)
174173

175-
@fixture(scope="class")
174+
@pytest.fixture()
176175
async def client(self, app_w_deps: FastAPI):
177176
async with AsyncClient(app=app_w_deps, base_url="http://test") as client:
178177
yield client

tests/test_atomic/test_dependencies.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from typing import ClassVar
22

33
import pytest
4-
from fastapi import Depends, Query, status
4+
from fastapi import Depends, Query, status, FastAPI
55
from httpx import AsyncClient
6-
from pytest_asyncio import fixture
76

87
from fastapi_jsonapi.misc.sqla.generics.base import DetailViewBaseGeneric, ListViewBaseGeneric
98
from fastapi_jsonapi.views.utils import (
@@ -100,8 +99,8 @@ def app_w_deps(self, resource_type):
10099
class_detail=UserCustomDetailView,
101100
)
102101

103-
@fixture(scope="class")
104-
async def client(self, app_w_deps):
102+
@pytest.fixture()
103+
async def client(self, app_w_deps: FastAPI):
105104
async with AsyncClient(app=app_w_deps, base_url="http://test") as client:
106105
yield client
107106

0 commit comments

Comments
 (0)