Skip to content

Commit

Permalink
Prevent an uncaught exception warning in a test suite thread (#635)
Browse files Browse the repository at this point in the history
After avoiding that warning, a ResourceWarning must be caught
due to an underlying event loop not getting closed.
  • Loading branch information
kurtmckee authored Jun 25, 2024
1 parent 39d1a2a commit a7f83db
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/middleware/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ def test_event_loop_thread_start():

def test_event_loop_thread_start_timeout():
thread = EventLoopThread(logger=get_logger(__name__))
thread.loop = mock.Mock()
thread.loop.run_forever.side_effect = RuntimeError("fail")
with pytest.raises(RuntimeError):
loop_mock = mock.Mock()
# Store the original thread loop and replace it with a mock.
original_loop = thread.loop
thread.loop = loop_mock
with pytest.raises(RuntimeError, match="Event loop failed to start"):
thread.start(timeout=0.1)
# Close the original event loop to prevent a ResourceWarning.
original_loop.close()


def test_event_loop_thread_run_coroutine(started_thread: EventLoopThread):
Expand Down

0 comments on commit a7f83db

Please sign in to comment.