Skip to content

Commit

Permalink
Eliminate a test ordering dependency (#636)
Browse files Browse the repository at this point in the history
If `test_async_to_sync` runs immediately before `test_async_to_sync_no_thread`,
the "no thread" test will fail to raise `RuntimeError`
because the module-level `_event_loop_thread` variable will still be set
(although it will be a mock, not a real thread).
  • Loading branch information
kurtmckee authored Jun 25, 2024
1 parent a7f83db commit cfcf4fa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/middleware/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ def test_async_to_sync(get_event_loop_thread_mocked):
set_event_loop_thread(thread)
fn = async_to_sync(async_fn)
actual = fn(2)
thread.run_coroutine.assert_called_once()
assert actual is thread.run_coroutine()
try:
thread.run_coroutine.assert_called_once()
assert actual is thread.run_coroutine.return_value
finally:
set_event_loop_thread(None)


def test_async_to_sync_with_actual_thread(started_thread):
Expand Down

0 comments on commit cfcf4fa

Please sign in to comment.