Skip to content

Instantly share code, notes, and snippets.

@phildini
Created May 4, 2020 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phildini/0424f6a6f30682d19002e60847f6989a to your computer and use it in GitHub Desktop.
Save phildini/0424f6a6f30682d19002e60847f6989a to your computer and use it in GitHub Desktop.
Test run channels
(websockets-test) phildini@Philips-MacBook-Pro-2 websockets-test % pytest test_consumers.py
============================= test session starts ==============================
platform darwin -- Python 3.7.6, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
django: settings: websocketstest.settings (from ini)
rootdir: /Users/phildini/websockets-test, inifile: pytest.ini
plugins: django-3.9.0, asyncio-0.11.0
collected 3 items
test_consumers.py .FF [100%]
=================================== FAILURES ===================================
______________________ TestWebsockets.test_receives_data _______________________
self = <channels.testing.websocket.WebsocketCommunicator object at 0x10a666a90>
timeout = 1
async def receive_output(self, timeout=1):
"""
Receives a single message from the application, with optional timeout.
"""
# Make sure there's not an exception to raise from the task
if self.future.done():
self.future.result()
# Wait and receive the message
try:
async with async_timeout(timeout):
> return await self.output_queue.get()
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/testing.py:74:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Queue at 0x10a666fd0 maxsize=0 tasks=1>
async def get(self):
"""Remove and return an item from the queue.
If queue is empty, wait until an item is available.
"""
while self.empty():
getter = self._loop.create_future()
self._getters.append(getter)
try:
> await getter
E concurrent.futures._base.CancelledError
/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/queues.py:159: CancelledError
During handling of the above exception, another exception occurred:
self = <test_consumers.TestWebsockets object at 0x10a659f10>
settings = <pytest_django.fixtures.SettingsWrapper object at 0x10a666d50>
async def test_receives_data(self, settings):
communicator = WebsocketCommunicator(
application=application, path="/ws/notifications/"
)
connected, _ = await communicator.connect()
assert connected
await communicator.send_json_to({"type": "notify", "data": "who knows"})
> response = await communicator.receive_json_from()
test_consumers.py:35:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/channels/testing/websocket.py:93: in receive_json_from
payload = await self.receive_from(timeout)
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/channels/testing/websocket.py:72: in receive_from
response = await self.receive_output(timeout)
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/testing.py:85: in receive_output
raise e
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/testing.py:74: in receive_output
return await self.output_queue.get()
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/timeout.py:68: in __aexit__
self._do_exit(exc_type)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <asgiref.timeout.timeout object at 0x10a693790>
exc_type = <class 'concurrent.futures._base.CancelledError'>
def _do_exit(self, exc_type: Type[BaseException]) -> None:
if exc_type is asyncio.CancelledError and self._cancelled:
self._cancel_handler = None
self._task = None
> raise asyncio.TimeoutError
E concurrent.futures._base.TimeoutError
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/timeout.py:105: TimeoutError
----------------------------- Captured stdout call -----------------------------
{'type': 'notify', 'data': 'who knows'}
Here we are
______________________________ test_receives_data ______________________________
self = <channels.testing.websocket.WebsocketCommunicator object at 0x10a6ff210>
timeout = 1
async def receive_output(self, timeout=1):
"""
Receives a single message from the application, with optional timeout.
"""
# Make sure there's not an exception to raise from the task
if self.future.done():
self.future.result()
# Wait and receive the message
try:
async with async_timeout(timeout):
> return await self.output_queue.get()
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/testing.py:74:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Queue at 0x10a6ff850 maxsize=0 tasks=1>
async def get(self):
"""Remove and return an item from the queue.
If queue is empty, wait until an item is available.
"""
while self.empty():
getter = self._loop.create_future()
self._getters.append(getter)
try:
> await getter
E concurrent.futures._base.CancelledError
/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/queues.py:159: CancelledError
During handling of the above exception, another exception occurred:
settings = <pytest_django.fixtures.SettingsWrapper object at 0x10a6ff590>
@pytest.mark.asyncio
async def test_receives_data(settings):
communicator = WebsocketCommunicator(
application=application, path="/ws/notifications/"
)
connected, _ = await communicator.connect()
assert connected
await communicator.send_json_to({"type": "notify", "data": "who knows"})
> response = await communicator.receive_json_from()
test_consumers.py:47:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/channels/testing/websocket.py:93: in receive_json_from
payload = await self.receive_from(timeout)
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/channels/testing/websocket.py:72: in receive_from
response = await self.receive_output(timeout)
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/testing.py:85: in receive_output
raise e
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/testing.py:74: in receive_output
return await self.output_queue.get()
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/timeout.py:68: in __aexit__
self._do_exit(exc_type)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <asgiref.timeout.timeout object at 0x10a6e9c90>
exc_type = <class 'concurrent.futures._base.CancelledError'>
def _do_exit(self, exc_type: Type[BaseException]) -> None:
if exc_type is asyncio.CancelledError and self._cancelled:
self._cancel_handler = None
self._task = None
> raise asyncio.TimeoutError
E concurrent.futures._base.TimeoutError
../.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/asgiref/timeout.py:105: TimeoutError
----------------------------- Captured stdout call -----------------------------
{'type': 'notify', 'data': 'who knows'}
Here we are
=============================== warnings summary ===============================
/Users/phildini/.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/model_mommy/__init__.py:7
/Users/phildini/.local/share/virtualenvs/websockets-test-asynguQ3/lib/python3.7/site-packages/model_mommy/__init__.py:7: DeprecationWarning: Important: model_mommy is no longer maintained. Please use model_bakery instead: https://pypi.org/project/model-bakery/
warnings.warn('Important: model_mommy is no longer maintained. Please use model_bakery instead: https://pypi.org/project/model-bakery/', DeprecationWarning)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================== short test summary info ============================
FAILED test_consumers.py::TestWebsockets::test_receives_data - concurrent.fut...
FAILED test_consumers.py::test_receives_data - concurrent.futures._base.Timeo...
==================== 2 failed, 1 passed, 1 warning in 2.33s ====================
(websockets-test) phildini@Philips-MacBook-Pro-2 websockets-test %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment