Skip to content

Commit 99ea07e

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

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
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.

app/services/location/csbs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44

55
from asyncache import cached
6+
67
from cachetools import TTLCache
78

89
from ...coordinates import Coordinates

app/services/location/jhu.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44

55
from asyncache import cached
6+
67
from cachetools import TTLCache
78

89
from ...coordinates import Coordinates

tests/conftest.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
55
"""
66
import datetime
77
import os
8-
from contextlib import asynccontextmanager
9-
from unittest import mock
108

119
import pytest
1210
from async_asgi_testclient import TestClient as AsyncTestClient
13-
from fastapi.testclient import TestClient
1411

1512
from app.main import APP
1613
from app.utils import httputils
14+
from fastapi.testclient import TestClient
15+
16+
try:
17+
from unittest.mock import AsyncMock
18+
except ImportError:
19+
# Python 3.7 backwards compat
20+
from asyncmock import AsyncMock
21+
22+
try:
23+
from contextlib import asynccontextmanager
24+
except ImportError:
25+
# Python 3.6 backwards compat
26+
from async_generator import asynccontextmanager
27+
28+
1729

1830

1931
@pytest.fixture
@@ -80,7 +92,7 @@ def mock_client_session_class(request):
8092
See: https://docs.pytest.org/en/5.4.1/unittest.html#mixing-pytest-fixtures-into-unittest-testcase-subclasses-using-marks
8193
"""
8294

83-
httputils.CLIENT_SESSION = request.cls.mock_client_session = mock.AsyncMock()
95+
httputils.CLIENT_SESSION = request.cls.mock_client_session = AsyncMock()
8496
httputils.CLIENT_SESSION.get = mocked_session_get
8597
try:
8698
yield
@@ -94,7 +106,7 @@ async def mock_client_session():
94106
instance.
95107
"""
96108

97-
httputils.CLIENT_SESSION = mock.AsyncMock()
109+
httputils.CLIENT_SESSION = AsyncMock()
98110
httputils.CLIENT_SESSION.get = mocked_session_get
99111
try:
100112
yield httputils.CLIENT_SESSION

0 commit comments

Comments
 (0)