You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I was writing tests for django-channels async consumers and middlewares. For writing these tests I am using also pytest-randomly and django-channelInMemoryChannelLayer.
When tests are running without pytest-randomly (with flag -p no:randomly) tests are passing, however with pytest-randomly plugin on I get exceptions like:
RuntimeError: Task <Task pending name='Task-49' coro=<InMemoryChannelLayer.receive() running at /usr/local/lib/python3.8/site-packages/channels/layers.py:250> cb=[_wait.<locals>._on_completion() at /usr/local/lib/python3.8/asyncio/tasks.py:515] created at /usr/local/lib/python3.8/site-packages/channels/utils.py:40> got Future <Future pending created at /usr/local/lib/python3.8/asyncio/base_events.py:422> attached to a different loop
When I add event_loop session-scoped fixture like suggested in #38 (comment) everything works like a charm even with pytest-randomly.
Do you have any idea why this is happening?
The text was updated successfully, but these errors were encountered:
It's probably interfering with the way we generate the event loop and initialize async fixtures. Feel free to poke around yourself and see if there's an easy fix :)
I would start by adding print statements to the existing request-scoped event loop fixture
I managed to find the root of the issue, and it's not related to the pytest-asyncio ;)
Basically, InMemoryChannelLayer is using random.choice() to generate new channels names, pytest-randomly is controlling random seed for each test, so it's common to get identical channel name for many tests and finally, channels aren't automatically flushed at the end of each test and this means that channels' Queues are reused, but they were created/bound to the previous event loop, so RuntimeError is raised.
Hi 👋
first of all big thanks for this awesome plugin!
Recently I was writing tests for
django-channels
async consumers and middlewares. For writing these tests I am using alsopytest-randomly
anddjango-channel
InMemoryChannelLayer
.When tests are running without
pytest-randomly
(with flag-p no:randomly
) tests are passing, however withpytest-randomly
plugin on I get exceptions like:When I add
event_loop
session-scoped fixture like suggested in #38 (comment) everything works like a charm even withpytest-randomly
.Do you have any idea why this is happening?
The text was updated successfully, but these errors were encountered: