9
9
from unittest import mock
10
10
11
11
import pytest
12
+ import pytest_asyncio
12
13
from pydantic import ValidationError
13
14
14
15
from aredis_om import (
22
23
# We need to run this check as sync code (during tests) even in async mode
23
24
# because we call it in the top-level module scope.
24
25
from redis_om import has_redisearch
25
-
26
+ from tests . conftest import py_test_mark_asyncio
26
27
27
28
if not has_redisearch ():
28
29
pytestmark = pytest .mark .skip
29
30
30
31
today = datetime .date .today ()
31
32
32
33
33
- @pytest .fixture
34
+ @pytest_asyncio .fixture
34
35
async def m (key_prefix , redis ):
35
36
class BaseHashModel (HashModel , abc .ABC ):
36
37
class Meta :
@@ -60,7 +61,7 @@ class Meta:
60
61
)
61
62
62
63
63
- @pytest .fixture
64
+ @pytest_asyncio .fixture
64
65
async def members (m ):
65
66
member1 = m .Member (
66
67
first_name = "Andrew" ,
@@ -95,7 +96,7 @@ async def members(m):
95
96
yield member1 , member2 , member3
96
97
97
98
98
- @pytest . mark . asyncio
99
+ @py_test_mark_asyncio
99
100
async def test_exact_match_queries (members , m ):
100
101
member1 , member2 , member3 = members
101
102
@@ -129,7 +130,7 @@ async def test_exact_match_queries(members, m):
129
130
assert actual == [member2 ]
130
131
131
132
132
- @pytest . mark . asyncio
133
+ @py_test_mark_asyncio
133
134
async def test_full_text_search_queries (members , m ):
134
135
member1 , member2 , member3 = members
135
136
@@ -142,7 +143,7 @@ async def test_full_text_search_queries(members, m):
142
143
assert actual == [member1 , member3 ]
143
144
144
145
145
- @pytest . mark . asyncio
146
+ @py_test_mark_asyncio
146
147
async def test_recursive_query_resolution (members , m ):
147
148
member1 , member2 , member3 = members
148
149
@@ -157,7 +158,7 @@ async def test_recursive_query_resolution(members, m):
157
158
assert actual == [member2 , member1 , member3 ]
158
159
159
160
160
- @pytest . mark . asyncio
161
+ @py_test_mark_asyncio
161
162
async def test_tag_queries_boolean_logic (members , m ):
162
163
member1 , member2 , member3 = members
163
164
@@ -172,7 +173,7 @@ async def test_tag_queries_boolean_logic(members, m):
172
173
assert actual == [member1 , member3 ]
173
174
174
175
175
- @pytest . mark . asyncio
176
+ @py_test_mark_asyncio
176
177
async def test_tag_queries_punctuation (m ):
177
178
member1 = m .Member (
178
179
first_name = "Andrew, the Michael" ,
@@ -210,7 +211,7 @@ async def test_tag_queries_punctuation(m):
210
211
assert results == [member2 ]
211
212
212
213
213
- @pytest . mark . asyncio
214
+ @py_test_mark_asyncio
214
215
async def test_tag_queries_negation (members , m ):
215
216
member1 , member2 , member3 = members
216
217
@@ -282,7 +283,7 @@ async def test_tag_queries_negation(members, m):
282
283
assert actual == [member3 ]
283
284
284
285
285
- @pytest . mark . asyncio
286
+ @py_test_mark_asyncio
286
287
async def test_numeric_queries (members , m ):
287
288
member1 , member2 , member3 = members
288
289
@@ -313,7 +314,7 @@ async def test_numeric_queries(members, m):
313
314
assert actual == [member2 , member1 ]
314
315
315
316
316
- @pytest . mark . asyncio
317
+ @py_test_mark_asyncio
317
318
async def test_sorting (members , m ):
318
319
member1 , member2 , member3 = members
319
320
@@ -357,7 +358,8 @@ def test_validation_passes(m):
357
358
)
358
359
assert member .first_name == "Andrew"
359
360
360
- @pytest .mark .asyncio
361
+
362
+ @py_test_mark_asyncio
361
363
async def test_retrieve_first (m ):
362
364
member = m .Member (
363
365
first_name = "Simon" ,
@@ -395,7 +397,8 @@ async def test_retrieve_first(m):
395
397
first_one = await m .Member .find ().sort_by ("age" ).first ()
396
398
assert first_one == member3
397
399
398
- @pytest .mark .asyncio
400
+
401
+ @py_test_mark_asyncio
399
402
async def test_saves_model_and_creates_pk (m ):
400
403
member = m .Member (
401
404
first_name = "Andrew" ,
@@ -411,7 +414,8 @@ async def test_saves_model_and_creates_pk(m):
411
414
member2 = await m .Member .get (member .pk )
412
415
assert member2 == member
413
416
414
- @pytest .mark .asyncio
417
+
418
+ @py_test_mark_asyncio
415
419
async def test_all_pks (m ):
416
420
member = m .Member (
417
421
first_name = "Simon" ,
@@ -441,7 +445,8 @@ async def test_all_pks(m):
441
445
442
446
assert len (pk_list ) == 2
443
447
444
- @pytest .mark .asyncio
448
+
449
+ @py_test_mark_asyncio
445
450
async def test_delete (m ):
446
451
member = m .Member (
447
452
first_name = "Simon" ,
@@ -457,7 +462,7 @@ async def test_delete(m):
457
462
assert response == 1
458
463
459
464
460
- @pytest . mark . asyncio
465
+ @py_test_mark_asyncio
461
466
async def test_expire (m ):
462
467
member = m .Member (
463
468
first_name = "Expire" ,
@@ -521,7 +526,7 @@ class InvalidMember(m.BaseHashModel):
521
526
friend_ids : List [str ]
522
527
523
528
524
- @pytest . mark . asyncio
529
+ @py_test_mark_asyncio
525
530
async def test_saves_many (m ):
526
531
member1 = m .Member (
527
532
first_name = "Andrew" ,
@@ -547,22 +552,22 @@ async def test_saves_many(m):
547
552
assert await m .Member .get (pk = member2 .pk ) == member2
548
553
549
554
550
- @pytest . mark . asyncio
555
+ @py_test_mark_asyncio
551
556
async def test_updates_a_model (members , m ):
552
557
member1 , member2 , member3 = members
553
558
await member1 .update (last_name = "Smith" )
554
559
member = await m .Member .get (member1 .pk )
555
560
assert member .last_name == "Smith"
556
561
557
562
558
- @pytest . mark . asyncio
563
+ @py_test_mark_asyncio
559
564
async def test_paginate_query (members , m ):
560
565
member1 , member2 , member3 = members
561
566
actual = await m .Member .find ().sort_by ("age" ).all (batch_size = 1 )
562
567
assert actual == [member2 , member1 , member3 ]
563
568
564
569
565
- @pytest . mark . asyncio
570
+ @py_test_mark_asyncio
566
571
async def test_access_result_by_index_cached (members , m ):
567
572
member1 , member2 , member3 = members
568
573
query = m .Member .find ().sort_by ("age" )
@@ -577,7 +582,7 @@ async def test_access_result_by_index_cached(members, m):
577
582
assert not mock_db .called
578
583
579
584
580
- @pytest . mark . asyncio
585
+ @py_test_mark_asyncio
581
586
async def test_access_result_by_index_not_cached (members , m ):
582
587
member1 , member2 , member3 = members
583
588
query = m .Member .find ().sort_by ("age" )
0 commit comments