Skip to content

Commit 4554636

Browse files
committed
Allow collection of tests even if aiohttp isn't installed
1 parent cdbdda1 commit 4554636

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

tests/test_aiohttp.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
try:
2+
from aiohttp import WSMsgType
3+
from graphql_ws.aiohttp import AiohttpConnectionContext, AiohttpSubscriptionServer
4+
except ImportError: # pragma: no cover
5+
WSMsgType = None
6+
17
from unittest import mock
28

39
import pytest
4-
from aiohttp import WSMsgType
510

6-
from graphql_ws.aiohttp import AiohttpConnectionContext, AiohttpSubscriptionServer
711
from graphql_ws.base import ConnectionClosedException
812

13+
if_aiohttp_installed = pytest.mark.skipif(
14+
WSMsgType is None, reason="aiohttp is not installed"
15+
)
16+
917

1018
class AsyncMock(mock.Mock):
1119
def __call__(self, *args, **kwargs):
12-
1320
async def coro():
1421
return super(AsyncMock, self).__call__(*args, **kwargs)
1522

@@ -24,6 +31,7 @@ def mock_ws():
2431
return ws
2532

2633

34+
@if_aiohttp_installed
2735
@pytest.mark.asyncio
2836
class TestConnectionContext:
2937
async def test_receive_good_data(self, mock_ws):
@@ -69,5 +77,6 @@ async def test_close(self, mock_ws):
6977
mock_ws.close.assert_called_with(code=123)
7078

7179

80+
@if_aiohttp_installed
7281
def test_subscription_server_smoke():
7382
AiohttpSubscriptionServer(schema=None)

0 commit comments

Comments
 (0)