Skip to content

Commit 935d53b

Browse files
author
Simon Prickett
authored
Merge pull request #225 from moznuy/fix/119
Fix DeprecationWarning '@pytest.fixture'
2 parents 84106b6 + 85540c0 commit 935d53b

9 files changed

+88
-63
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ clean:
3333
rm -rf build
3434
rm -rf dist
3535
rm -rf redis_om
36+
rm -rf tests_sync
3637
docker-compose down
3738

3839

aredis_om/connections.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import aioredis
44

5+
56
URL = os.environ.get("REDIS_OM_URL", None)
67

78

make_sync.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"aredis_om": "redis_om",
88
"aioredis": "redis",
99
":tests.": ":tests_sync.",
10+
"pytest_asyncio": "pytest",
11+
"py_test_mark_asyncio": "py_test_mark_sync",
1012
}
1113

1214

pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
asyncio_mode = strict

tests/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
TEST_PREFIX = "redis-om:testing"
1010

1111

12+
py_test_mark_asyncio = pytest.mark.asyncio
13+
14+
15+
# "pytest_mark_sync" causes problem in pytest
16+
def py_test_mark_sync(f):
17+
return f # no-op decorator
18+
19+
1220
@pytest.fixture(scope="session")
1321
def event_loop(request):
1422
loop = asyncio.get_event_loop_policy().new_event_loop()

tests/test_hash_model.py

+26-21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from unittest import mock
1010

1111
import pytest
12+
import pytest_asyncio
1213
from pydantic import ValidationError
1314

1415
from aredis_om import (
@@ -22,15 +23,15 @@
2223
# We need to run this check as sync code (during tests) even in async mode
2324
# because we call it in the top-level module scope.
2425
from redis_om import has_redisearch
25-
26+
from tests.conftest import py_test_mark_asyncio
2627

2728
if not has_redisearch():
2829
pytestmark = pytest.mark.skip
2930

3031
today = datetime.date.today()
3132

3233

33-
@pytest.fixture
34+
@pytest_asyncio.fixture
3435
async def m(key_prefix, redis):
3536
class BaseHashModel(HashModel, abc.ABC):
3637
class Meta:
@@ -60,7 +61,7 @@ class Meta:
6061
)
6162

6263

63-
@pytest.fixture
64+
@pytest_asyncio.fixture
6465
async def members(m):
6566
member1 = m.Member(
6667
first_name="Andrew",
@@ -95,7 +96,7 @@ async def members(m):
9596
yield member1, member2, member3
9697

9798

98-
@pytest.mark.asyncio
99+
@py_test_mark_asyncio
99100
async def test_exact_match_queries(members, m):
100101
member1, member2, member3 = members
101102

@@ -129,7 +130,7 @@ async def test_exact_match_queries(members, m):
129130
assert actual == [member2]
130131

131132

132-
@pytest.mark.asyncio
133+
@py_test_mark_asyncio
133134
async def test_full_text_search_queries(members, m):
134135
member1, member2, member3 = members
135136

@@ -142,7 +143,7 @@ async def test_full_text_search_queries(members, m):
142143
assert actual == [member1, member3]
143144

144145

145-
@pytest.mark.asyncio
146+
@py_test_mark_asyncio
146147
async def test_recursive_query_resolution(members, m):
147148
member1, member2, member3 = members
148149

@@ -157,7 +158,7 @@ async def test_recursive_query_resolution(members, m):
157158
assert actual == [member2, member1, member3]
158159

159160

160-
@pytest.mark.asyncio
161+
@py_test_mark_asyncio
161162
async def test_tag_queries_boolean_logic(members, m):
162163
member1, member2, member3 = members
163164

@@ -172,7 +173,7 @@ async def test_tag_queries_boolean_logic(members, m):
172173
assert actual == [member1, member3]
173174

174175

175-
@pytest.mark.asyncio
176+
@py_test_mark_asyncio
176177
async def test_tag_queries_punctuation(m):
177178
member1 = m.Member(
178179
first_name="Andrew, the Michael",
@@ -210,7 +211,7 @@ async def test_tag_queries_punctuation(m):
210211
assert results == [member2]
211212

212213

213-
@pytest.mark.asyncio
214+
@py_test_mark_asyncio
214215
async def test_tag_queries_negation(members, m):
215216
member1, member2, member3 = members
216217

@@ -282,7 +283,7 @@ async def test_tag_queries_negation(members, m):
282283
assert actual == [member3]
283284

284285

285-
@pytest.mark.asyncio
286+
@py_test_mark_asyncio
286287
async def test_numeric_queries(members, m):
287288
member1, member2, member3 = members
288289

@@ -313,7 +314,7 @@ async def test_numeric_queries(members, m):
313314
assert actual == [member2, member1]
314315

315316

316-
@pytest.mark.asyncio
317+
@py_test_mark_asyncio
317318
async def test_sorting(members, m):
318319
member1, member2, member3 = members
319320

@@ -357,7 +358,8 @@ def test_validation_passes(m):
357358
)
358359
assert member.first_name == "Andrew"
359360

360-
@pytest.mark.asyncio
361+
362+
@py_test_mark_asyncio
361363
async def test_retrieve_first(m):
362364
member = m.Member(
363365
first_name="Simon",
@@ -395,7 +397,8 @@ async def test_retrieve_first(m):
395397
first_one = await m.Member.find().sort_by("age").first()
396398
assert first_one == member3
397399

398-
@pytest.mark.asyncio
400+
401+
@py_test_mark_asyncio
399402
async def test_saves_model_and_creates_pk(m):
400403
member = m.Member(
401404
first_name="Andrew",
@@ -411,7 +414,8 @@ async def test_saves_model_and_creates_pk(m):
411414
member2 = await m.Member.get(member.pk)
412415
assert member2 == member
413416

414-
@pytest.mark.asyncio
417+
418+
@py_test_mark_asyncio
415419
async def test_all_pks(m):
416420
member = m.Member(
417421
first_name="Simon",
@@ -441,7 +445,8 @@ async def test_all_pks(m):
441445

442446
assert len(pk_list) == 2
443447

444-
@pytest.mark.asyncio
448+
449+
@py_test_mark_asyncio
445450
async def test_delete(m):
446451
member = m.Member(
447452
first_name="Simon",
@@ -457,7 +462,7 @@ async def test_delete(m):
457462
assert response == 1
458463

459464

460-
@pytest.mark.asyncio
465+
@py_test_mark_asyncio
461466
async def test_expire(m):
462467
member = m.Member(
463468
first_name="Expire",
@@ -521,7 +526,7 @@ class InvalidMember(m.BaseHashModel):
521526
friend_ids: List[str]
522527

523528

524-
@pytest.mark.asyncio
529+
@py_test_mark_asyncio
525530
async def test_saves_many(m):
526531
member1 = m.Member(
527532
first_name="Andrew",
@@ -547,22 +552,22 @@ async def test_saves_many(m):
547552
assert await m.Member.get(pk=member2.pk) == member2
548553

549554

550-
@pytest.mark.asyncio
555+
@py_test_mark_asyncio
551556
async def test_updates_a_model(members, m):
552557
member1, member2, member3 = members
553558
await member1.update(last_name="Smith")
554559
member = await m.Member.get(member1.pk)
555560
assert member.last_name == "Smith"
556561

557562

558-
@pytest.mark.asyncio
563+
@py_test_mark_asyncio
559564
async def test_paginate_query(members, m):
560565
member1, member2, member3 = members
561566
actual = await m.Member.find().sort_by("age").all(batch_size=1)
562567
assert actual == [member2, member1, member3]
563568

564569

565-
@pytest.mark.asyncio
570+
@py_test_mark_asyncio
566571
async def test_access_result_by_index_cached(members, m):
567572
member1, member2, member3 = members
568573
query = m.Member.find().sort_by("age")
@@ -577,7 +582,7 @@ async def test_access_result_by_index_cached(members, m):
577582
assert not mock_db.called
578583

579584

580-
@pytest.mark.asyncio
585+
@py_test_mark_asyncio
581586
async def test_access_result_by_index_not_cached(members, m):
582587
member1, member2, member3 = members
583588
query = m.Member.find().sort_by("age")

0 commit comments

Comments
 (0)