Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
19 changes: 19 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@
setup_logging(TEST_CONFIG["LOG"])


@pytest.fixture
def current_event_loop():
"""
Provide a current event loop on the main thread for synchronous tests that

@wojcikstefan wojcikstefan Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does the "on the main thread" mean in this context? What other threads are used?

And what does it mean to "drive the loop"? Is that some standard vocabulary? Why is calling shark.start "driving" the loop?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does the "on the main thread" mean in this context? What other threads are used?

That was referencing the error message: RuntimeError: There is no current event loop in thread 'MainThread'. Updated the description to be more clear.

And what does it mean to "drive the loop"? Is that some standard vocabulary? Why is calling shark.start "driving" the loop?

This is some weird vocab claude used when I asked it to write the comment and description. I have rewritten the description to describe the exact issue without the strange terminology. What it meant was that start() calls asyncio.get_event_loop() and loop.run_until_complete().

drive the loop themselves (e.g. they call ``shark.start()`` directly).

pytest-asyncio no longer sets a current event loop, and
``asyncio.get_event_loop()`` no longer creates one implicitly, so these
tests need an explicit loop set up and torn down around them.
Comment thread
wojcikstefan marked this conversation as resolved.
Outdated
"""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
yield loop
loop.close()
asyncio.set_event_loop(None)


class aioresponses_delayed(aioresponses): # noqa
"""
Just like aioresponses, but slightly delays POST requests.
Expand All @@ -134,6 +151,7 @@ async def close(self):
await self.session.on_close()


@pytest.mark.usefixtures("current_event_loop")
class TestShark:
def test_shark_init(self):
shark = SocketShark(TEST_CONFIG)
Expand Down Expand Up @@ -2522,6 +2540,7 @@ async def dummy_send(*args):
await shark.shutdown()


@pytest.mark.usefixtures("current_event_loop")
class TestWebsocket:
"""
Test an actual WebSocket connection.
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

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

Loading