crossbario / crossbario/autobahn-python
a Future constructor is missing the `loop` kwarg
@meejah is already working on this.
Since Mar 9, 2021.
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 768
- PR merge metrics
- No merged PRs in 30d
Description
There's a Future created by the _consume method of autobahn.asyncio.websocket.WebSocketAdapterProtocol.
It is not passing the loop kwarg, which leads to NotImplementedErrorwhen the implicit default 'global' loop is not being used. If I understand correctly.
I am guessing it's possible to reproduce this simply by creating a custom loop, rather than asking for the default via asyncio.get_event_loop(), and passing that to the connection factory.
I encountered the issue when creating what amounts to an autobahn websocket connection test using py.test (with help from the pytest-asyncio package that provides some useful asyncio testing fixtures). To repeat that, write a test function to make a websocket connection so that:
- the test is decorated with the
pytest.mark.asynciodecorator, with theforbid_global_loopparameter set toTrue) - the
event_loopfixture is used for the test, and explicitly used as the loop passed to autobahn
So the 'stanza' for such a test becomes like this:
from pytest import mark
@mark.asyncio(forbid_global_loop=True)
async def test_ws_connect(event_loop):
"some test that connects"
...
Then, upon connect, the NotImplementedError will be raised.
As for fixing the issue, the loop appears to be available in the protocol as self.transport._loop, and I can confirm that passing it as loopkwarg fixes the issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.