Skip to content

Commit 07e4074

Browse files
committed
Fallback to pypi-provided backports for async test utils
1 parent f9b0ce1 commit 07e4074

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ verify_ssl = true
55

66
[dev-packages]
77
async-asgi-testclient = "*"
8+
async_generator = "*"
9+
asyncmock = "*"
810
bandit = "*"
911
black = "==19.10b0"
1012
coveralls = "*"

Pipfile.lock

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/conftest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
"""
66
import datetime
77
import os
8-
from contextlib import asynccontextmanager
9-
from unittest import mock
8+
9+
try:
10+
from unittest.mock import AsyncMock
11+
except ImportError:
12+
# Python 3.7 backwards compat
13+
from asyncmock import AsyncMock
14+
15+
try:
16+
from contextlib import asynccontextmanager
17+
except ImportError:
18+
# Python 3.6 backwards compat
19+
from async_generator import asynccontextmanager
1020

1121
import pytest
1222
from async_asgi_testclient import TestClient as AsyncTestClient
@@ -80,7 +90,7 @@ def mock_client_session_class(request):
8090
See: https://docs.pytest.org/en/5.4.1/unittest.html#mixing-pytest-fixtures-into-unittest-testcase-subclasses-using-marks
8191
"""
8292

83-
httputils.CLIENT_SESSION = request.cls.mock_client_session = mock.AsyncMock()
93+
httputils.CLIENT_SESSION = request.cls.mock_client_session = AsyncMock()
8494
httputils.CLIENT_SESSION.get = mocked_session_get
8595
try:
8696
yield
@@ -94,7 +104,7 @@ async def mock_client_session():
94104
instance.
95105
"""
96106

97-
httputils.CLIENT_SESSION = mock.AsyncMock()
107+
httputils.CLIENT_SESSION = AsyncMock()
98108
httputils.CLIENT_SESSION.get = mocked_session_get
99109
try:
100110
yield httputils.CLIENT_SESSION

0 commit comments

Comments
 (0)