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 @@ -631,6 +631,21 @@ def _temporary_event_loop_policy(policy: AbstractEventLoopPolicy) -> Iterator[No
631631 _set_event_loop (old_loop )
632632
633633
634+ @contextlib .contextmanager
635+ def _temporary_event_loop (loop :AbstractEventLoop ):
636+ try :
637+ old_event_loop = asyncio .get_event_loop ()
638+ except RuntimeError :
639+ old_event_loop = None
640+
641+ asyncio .set_event_loop (old_event_loop )
642+ try :
643+ yield
644+ finally :
645+ asyncio .set_event_loop (old_event_loop )
646+
647+
648+
634649def _get_event_loop_policy () -> AbstractEventLoopPolicy :
635650 with warnings .catch_warnings ():
636651 warnings .simplefilter ("ignore" , DeprecationWarning )
@@ -826,6 +841,9 @@ def _scoped_runner(
826841 RuntimeWarning ,
827842 )
828843
844+
845+
846+
829847 return _scoped_runner
830848
831849
@@ -834,6 +852,11 @@ def _scoped_runner(
834852 scope .value
835853 )
836854
855+ @pytest .fixture (scope = "session" , autouse = True )
856+ def new_event_loop () -> AbstractEventLoop :
857+ """Creates a new eventloop for different tests being ran"""
858+ return asyncio .new_event_loop ()
859+
837860
838861@pytest .fixture (scope = "session" , autouse = True )
839862def event_loop_policy () -> AbstractEventLoopPolicy :
You can’t perform that action at this time.
0 commit comments