Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fallback to pypi-provided backports for async test utils
  • Loading branch information
james-gray committed Apr 2, 2020
commit 99ea07e8a5fba816fe8afa1d2e4c21b94d4f067b
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ verify_ssl = true

[dev-packages]
async-asgi-testclient = "*"
async_generator = "*"
asyncmock = "*"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These back-ports should be adjusted so that they are only installed when required.
https://pipenv.readthedocs.io/en/latest/basics/#specifying-versions-of-a-package
https://pipenv.readthedocs.io/en/latest/advanced/#specifying-basically-anything

I'll try to do this tonight if I have a chance.
Thanks for all the notes, should make this easy.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, happy to help!

bandit = "*"
black = "==19.10b0"
coveralls = "*"
Expand Down
25 changes: 24 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime

from asyncache import cached

from cachetools import TTLCache

from ...coordinates import Coordinates
Expand Down
1 change: 1 addition & 0 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime

from asyncache import cached

from cachetools import TTLCache

from ...coordinates import Coordinates
Expand Down
22 changes: 17 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@
"""
import datetime
import os
from contextlib import asynccontextmanager
from unittest import mock

import pytest
from async_asgi_testclient import TestClient as AsyncTestClient
from fastapi.testclient import TestClient

from app.main import APP
from app.utils import httputils
from fastapi.testclient import TestClient

try:
from unittest.mock import AsyncMock
except ImportError:
# Python 3.7 backwards compat
from asyncmock import AsyncMock

try:
from contextlib import asynccontextmanager
except ImportError:
# Python 3.6 backwards compat
from async_generator import asynccontextmanager




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

httputils.CLIENT_SESSION = request.cls.mock_client_session = mock.AsyncMock()
httputils.CLIENT_SESSION = request.cls.mock_client_session = AsyncMock()
httputils.CLIENT_SESSION.get = mocked_session_get
try:
yield
Expand All @@ -94,7 +106,7 @@ async def mock_client_session():
instance.
"""

httputils.CLIENT_SESSION = mock.AsyncMock()
httputils.CLIENT_SESSION = AsyncMock()
httputils.CLIENT_SESSION.get = mocked_session_get
try:
yield httputils.CLIENT_SESSION
Expand Down