Skip to content

Commit c43b4b1

Browse files
committed
Remove dead code and simplify code in call_fixture_func
1 parent a91d035 commit c43b4b1

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

_pytest/python.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,29 +2326,20 @@ def fail_fixturefunc(fixturefunc, msg):
23262326
def call_fixture_func(fixturefunc, request, kwargs):
23272327
yieldctx = is_generator(fixturefunc)
23282328
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+
23372332
def teardown():
23382333
try:
2339-
next()
2334+
next(it)
23402335
except StopIteration:
23412336
pass
23422337
else:
23432338
fail_fixturefunc(fixturefunc,
23442339
"yield_fixture function has more than one 'yield'")
2340+
23452341
request.addfinalizer(teardown)
23462342
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.")
23522343
res = fixturefunc(**kwargs)
23532344
return res
23542345

0 commit comments

Comments
 (0)