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
546
546
_set_event_loop (old_loop )
547
547
548
548
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
+
549
564
def _get_event_loop_policy () -> AbstractEventLoopPolicy :
550
565
with warnings .catch_warnings ():
551
566
warnings .simplefilter ("ignore" , DeprecationWarning )
@@ -772,6 +787,9 @@ def _scoped_runner(
772
787
RuntimeWarning ,
773
788
)
774
789
790
+
791
+
792
+
775
793
return _scoped_runner
776
794
777
795
@@ -780,6 +798,11 @@ def _scoped_runner(
780
798
scope .value
781
799
)
782
800
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
+
783
806
784
807
@pytest .fixture (scope = "session" , autouse = True )
785
808
def event_loop_policy () -> AbstractEventLoopPolicy :
You can’t perform that action at this time.
0 commit comments