File tree Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Original file line number Diff line number Diff line change @@ -2326,29 +2326,20 @@ def fail_fixturefunc(fixturefunc, msg):
2326
2326
def call_fixture_func (fixturefunc , request , kwargs ):
2327
2327
yieldctx = is_generator (fixturefunc )
2328
2328
if yieldctx :
2329
- if not is_generator (fixturefunc ):
2330
- fail_fixturefunc (fixturefunc ,
2331
- msg = "yield_fixture requires yield statement in function" )
2332
- iter = fixturefunc (** kwargs )
2333
- next = getattr (iter , "__next__" , None )
2334
- if next is None :
2335
- next = getattr (iter , "next" )
2336
- res = next ()
2329
+ it = fixturefunc (** kwargs )
2330
+ res = next (it )
2331
+
2337
2332
def teardown ():
2338
2333
try :
2339
- next ()
2334
+ next (it )
2340
2335
except StopIteration :
2341
2336
pass
2342
2337
else :
2343
2338
fail_fixturefunc (fixturefunc ,
2344
2339
"yield_fixture function has more than one 'yield'" )
2340
+
2345
2341
request .addfinalizer (teardown )
2346
2342
else :
2347
- if is_generator (fixturefunc ):
2348
- fail_fixturefunc (fixturefunc ,
2349
- msg = "pytest.fixture functions cannot use ``yield``. "
2350
- "Instead write and return an inner function/generator "
2351
- "and let the consumer call and iterate over it." )
2352
2343
res = fixturefunc (** kwargs )
2353
2344
return res
2354
2345
You can’t perform that action at this time.
0 commit comments