File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -546,6 +546,21 @@ def _temporary_event_loop_policy(policy: AbstractEventLoopPolicy) -> Iterator[No
546546 _set_event_loop (old_loop )
547547
548548
549+ @contextlib .contextmanager
550+ def _temporary_event_loop (loop :AbstractEventLoop ):
551+ try :
552+ old_event_loop = asyncio .get_event_loop ()
553+ except RuntimeError :
554+ old_event_loop = None
555+
556+ asyncio .set_event_loop (old_event_loop )
557+ try :
558+ yield
559+ finally :
560+ asyncio .set_event_loop (old_event_loop )
561+
562+
563+
549564def _get_event_loop_policy () -> AbstractEventLoopPolicy :
550565 with warnings .catch_warnings ():
551566 warnings .simplefilter ("ignore" , DeprecationWarning )
@@ -772,6 +787,9 @@ def _scoped_runner(
772787 RuntimeWarning ,
773788 )
774789
790+
791+
792+
775793 return _scoped_runner
776794
777795
@@ -780,6 +798,11 @@ def _scoped_runner(
780798 scope .value
781799 )
782800
801+ @pytest .fixture (scope = "session" , autouse = True )
802+ def new_event_loop () -> AbstractEventLoop :
803+ """Creates a new eventloop for different tests being ran"""
804+ return asyncio .new_event_loop ()
805+
783806
784807@pytest .fixture (scope = "session" , autouse = True )
785808def event_loop_policy () -> AbstractEventLoopPolicy :
You can’t perform that action at this time.
0 commit comments