@@ -266,33 +266,24 @@ def counting_ask(self, n, tell_pending=True):
266266 Learner1D .ask = original_ask
267267
268268
269- def test_async_runner_without_event_loop ():
270- """Test that AsyncRunner works when no event loop exists .
269+ def test_async_runner_without_running_event_loop ():
270+ """Test that AsyncRunner works when no event loop is running .
271271
272272 In Python 3.10+, asyncio.get_event_loop() was deprecated when no running
273273 event loop exists. In Python 3.12+ it emits a DeprecationWarning, and in
274274 Python 3.14+ it raises a RuntimeError.
275275
276276 This test ensures AsyncRunner properly handles the case when no event
277- loop exists by creating one.
277+ loop is running by creating one.
278278
279279 Regression test for: https://github.com/python-adaptive/adaptive/issues/489
280280 """
281+ # Ensure no event loop is currently running
282+ with pytest .raises (RuntimeError , match = "no running event loop" ):
283+ asyncio .get_running_loop ()
281284
282- def run_in_thread ():
283- """Run AsyncRunner in a thread with no event loop."""
284- # Ensure no event loop exists in this thread
285- with pytest .raises (RuntimeError , match = "no.*event loop" ):
286- asyncio .get_running_loop ()
287-
288- # AsyncRunner should still work - it should create its own event loop
289- learner = Learner1D (linear , (- 1 , 1 ))
290- runner = AsyncRunner (learner , npoints_goal = 10 , executor = SequentialExecutor ())
291- runner .block_until_done ()
292- assert learner .npoints >= 10
293-
294- import threading
295-
296- thread = threading .Thread (target = run_in_thread )
297- thread .start ()
298- thread .join ()
285+ # AsyncRunner should still work - it should create its own event loop
286+ learner = Learner1D (linear , (- 1 , 1 ))
287+ runner = AsyncRunner (learner , npoints_goal = 10 , executor = SequentialExecutor ())
288+ runner .block_until_done ()
289+ assert learner .npoints >= 10
0 commit comments