@@ -967,17 +967,22 @@ def test_script_config():
967967 assert "whoda" in sm .magics ["cell" ]
968968
969969
970+ @pytest .fixture
971+ def event_loop ():
972+ yield asyncio .get_event_loop_policy ().get_event_loop ()
973+
974+
970975@dec .skip_iptest_but_not_pytest
971976@dec .skip_win32
972977@pytest .mark .skipif (
973978 sys .platform == "win32" , reason = "This test does not run under Windows"
974979)
975- def test_script_out ():
976- assert asyncio . get_event_loop () .is_running () is False
980+ def test_script_out (event_loop ):
981+ assert event_loop .is_running () is False
977982
978983 ip = get_ipython ()
979984 ip .run_cell_magic ("script" , "--out output sh" , "echo 'hi'" )
980- assert asyncio . get_event_loop () .is_running () is False
985+ assert event_loop .is_running () is False
981986 assert ip .user_ns ["output" ] == "hi\n "
982987
983988
@@ -986,11 +991,11 @@ def test_script_out():
986991@pytest .mark .skipif (
987992 sys .platform == "win32" , reason = "This test does not run under Windows"
988993)
989- def test_script_err ():
994+ def test_script_err (event_loop ):
990995 ip = get_ipython ()
991- assert asyncio . get_event_loop () .is_running () is False
996+ assert event_loop .is_running () is False
992997 ip .run_cell_magic ("script" , "--err error sh" , "echo 'hello' >&2" )
993- assert asyncio . get_event_loop () .is_running () is False
998+ assert event_loop .is_running () is False
994999 assert ip .user_ns ["error" ] == "hello\n "
9951000
9961001
@@ -1014,12 +1019,12 @@ def test_script_out_err():
10141019@pytest .mark .skipif (
10151020 sys .platform == "win32" , reason = "This test does not run under Windows"
10161021)
1017- async def test_script_bg_out ():
1022+ async def test_script_bg_out (event_loop ):
10181023 ip = get_ipython ()
10191024 ip .run_cell_magic ("script" , "--bg --out output sh" , "echo 'hi'" )
10201025 assert (await ip .user_ns ["output" ].read ()) == b"hi\n "
10211026 ip .user_ns ["output" ].close ()
1022- asyncio . get_event_loop () .stop ()
1027+ event_loop .stop ()
10231028
10241029
10251030@dec .skip_iptest_but_not_pytest
0 commit comments