File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -129,7 +129,12 @@ async def setup():
129
129
if kw not in request .keywords :
130
130
continue
131
131
policy = asyncio .get_event_loop_policy ()
132
- old_loop = policy .get_event_loop ()
132
+ try :
133
+ old_loop = policy .get_event_loop ()
134
+ except RuntimeError as exc :
135
+ if 'no current event loop' not in str (exc ):
136
+ raise
137
+ old_loop = None
133
138
policy .set_event_loop (loop )
134
139
fixturedef .addfinalizer (lambda : policy .set_event_loop (old_loop ))
135
140
Original file line number Diff line number Diff line change 7
7
8
8
9
9
@asyncio .coroutine
10
- def async_coro (loop ):
10
+ def async_coro (loop = None ):
11
11
"""A very simple coroutine."""
12
12
yield from asyncio .sleep (0 , loop = loop )
13
13
return 'ok'
@@ -143,3 +143,18 @@ def test_asyncio_marker_method(self, event_loop):
143
143
"""Test the asyncio pytest marker in a Test class."""
144
144
ret = yield from async_coro (event_loop )
145
145
assert ret == 'ok'
146
+
147
+
148
+ class TestUnexistingLoop :
149
+ @pytest .fixture
150
+ def remove_loop (self ):
151
+ old_loop = asyncio .get_event_loop ()
152
+ asyncio .set_event_loop (None )
153
+ yield
154
+ asyncio .set_event_loop (old_loop )
155
+
156
+ @pytest .mark .asyncio
157
+ def test_asyncio_marker_without_loop (self , remove_loop ):
158
+ """Test the asyncio pytest marker in a Test class."""
159
+ ret = yield from async_coro ()
160
+ assert ret == 'ok'
You can’t perform that action at this time.
0 commit comments