@@ -124,18 +124,15 @@ async def setup():
124
124
125
125
if fixturedef .argname == "event_loop" and 'asyncio' in request .keywords :
126
126
loop = outcome .get_result ()
127
- for kw in _markers_2_fixtures .keys ():
128
- if kw not in request .keywords :
129
- continue
130
- policy = asyncio .get_event_loop_policy ()
131
- try :
132
- old_loop = policy .get_event_loop ()
133
- except RuntimeError as exc :
134
- if 'no current event loop' not in str (exc ):
135
- raise
136
- old_loop = None
137
- policy .set_event_loop (loop )
138
- fixturedef .addfinalizer (lambda : policy .set_event_loop (old_loop ))
127
+ policy = asyncio .get_event_loop_policy ()
128
+ try :
129
+ old_loop = policy .get_event_loop ()
130
+ except RuntimeError as exc :
131
+ if 'no current event loop' not in str (exc ):
132
+ raise
133
+ old_loop = None
134
+ policy .set_event_loop (loop )
135
+ fixturedef .addfinalizer (lambda : policy .set_event_loop (old_loop ))
139
136
140
137
141
138
@pytest .hookimpl (tryfirst = True , hookwrapper = True )
@@ -144,14 +141,13 @@ def pytest_pyfunc_call(pyfuncitem):
144
141
Run asyncio marked test functions in an event loop instead of a normal
145
142
function call.
146
143
"""
147
- for marker_name , fixture_name in _markers_2_fixtures .items ():
148
- if marker_name in pyfuncitem .keywords :
149
- if getattr (pyfuncitem .obj , 'is_hypothesis_test' , False ):
150
- pyfuncitem .obj .hypothesis .inner_test = wrap_in_sync (
151
- pyfuncitem .obj .hypothesis .inner_test
152
- )
153
- else :
154
- pyfuncitem .obj = wrap_in_sync (pyfuncitem .obj )
144
+ if 'asyncio' in pyfuncitem .keywords :
145
+ if getattr (pyfuncitem .obj , 'is_hypothesis_test' , False ):
146
+ pyfuncitem .obj .hypothesis .inner_test = wrap_in_sync (
147
+ pyfuncitem .obj .hypothesis .inner_test
148
+ )
149
+ else :
150
+ pyfuncitem .obj = wrap_in_sync (pyfuncitem .obj )
155
151
yield
156
152
157
153
@@ -170,10 +166,9 @@ def inner(**kwargs):
170
166
171
167
172
168
def pytest_runtest_setup (item ):
173
- for marker , fixture in _markers_2_fixtures .items ():
174
- if marker in item .keywords and fixture not in item .fixturenames :
175
- # inject an event loop fixture for all async tests
176
- item .fixturenames .append (fixture )
169
+ if 'asyncio' in item .keywords and 'event_loop' not in item .fixturenames :
170
+ # inject an event loop fixture for all async tests
171
+ item .fixturenames .append ('event_loop' )
177
172
if item .get_closest_marker ("asyncio" ) is not None \
178
173
and not getattr (item .obj , 'hypothesis' , False ) \
179
174
and getattr (item .obj , 'is_hypothesis_test' , False ):
@@ -183,13 +178,6 @@ def pytest_runtest_setup(item):
183
178
)
184
179
185
180
186
- # maps marker to the name of the event loop fixture that will be available
187
- # to marked test functions
188
- _markers_2_fixtures = {
189
- 'asyncio' : 'event_loop' ,
190
- }
191
-
192
-
193
181
@pytest .yield_fixture
194
182
def event_loop (request ):
195
183
"""Create an instance of the default event loop for each test case."""
0 commit comments