Remove dead code and simplify code in call_fixture_func
This commit is contained in:
parent
ed69424917
commit
bdc29968b8
|
@ -2326,29 +2326,20 @@ def fail_fixturefunc(fixturefunc, msg):
|
||||||
def call_fixture_func(fixturefunc, request, kwargs):
|
def call_fixture_func(fixturefunc, request, kwargs):
|
||||||
yieldctx = is_generator(fixturefunc)
|
yieldctx = is_generator(fixturefunc)
|
||||||
if yieldctx:
|
if yieldctx:
|
||||||
if not is_generator(fixturefunc):
|
it = fixturefunc(**kwargs)
|
||||||
fail_fixturefunc(fixturefunc,
|
res = next(it)
|
||||||
msg="yield_fixture requires yield statement in function")
|
|
||||||
iter = fixturefunc(**kwargs)
|
|
||||||
next = getattr(iter, "__next__", None)
|
|
||||||
if next is None:
|
|
||||||
next = getattr(iter, "next")
|
|
||||||
res = next()
|
|
||||||
def teardown():
|
def teardown():
|
||||||
try:
|
try:
|
||||||
next()
|
next(it)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
fail_fixturefunc(fixturefunc,
|
fail_fixturefunc(fixturefunc,
|
||||||
"yield_fixture function has more than one 'yield'")
|
"yield_fixture function has more than one 'yield'")
|
||||||
|
|
||||||
request.addfinalizer(teardown)
|
request.addfinalizer(teardown)
|
||||||
else:
|
else:
|
||||||
if is_generator(fixturefunc):
|
|
||||||
fail_fixturefunc(fixturefunc,
|
|
||||||
msg="pytest.fixture functions cannot use ``yield``. "
|
|
||||||
"Instead write and return an inner function/generator "
|
|
||||||
"and let the consumer call and iterate over it.")
|
|
||||||
res = fixturefunc(**kwargs)
|
res = fixturefunc(**kwargs)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue