fix issue498: if a fixture finalizer fails, make sure that the fixture
is still invalidated. --HG-- branch : issue498
This commit is contained in:
parent
6efde60b8b
commit
ef7cb47b1e
|
@ -1,6 +1,9 @@
|
|||
NEXT (2.6)
|
||||
-----------------------------------
|
||||
|
||||
- fix issue498: if a fixture finalizer fails, make sure that
|
||||
the fixture is still invalidated.
|
||||
|
||||
- fix issue453: the result of the pytest_assertrepr_compare hook now gets
|
||||
it's newlines escaped so that format_exception does not blow up.
|
||||
|
||||
|
|
|
@ -1778,13 +1778,15 @@ class FixtureDef:
|
|||
self._finalizer.append(finalizer)
|
||||
|
||||
def finish(self):
|
||||
try:
|
||||
while self._finalizer:
|
||||
func = self._finalizer.pop()
|
||||
func()
|
||||
try:
|
||||
finally:
|
||||
# even if finalization fails, we invalidate
|
||||
# the cached fixture value
|
||||
if hasattr(self, "cached_result"):
|
||||
del self.cached_result
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def execute(self, request):
|
||||
# get required arguments and register our own finish()
|
||||
|
|
|
@ -2087,6 +2087,35 @@ class TestErrors:
|
|||
"*1 error*",
|
||||
])
|
||||
|
||||
def test_issue498_fixture_finalizer_failing(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def fix1(request):
|
||||
def f():
|
||||
raise KeyError
|
||||
request.addfinalizer(f)
|
||||
return object()
|
||||
|
||||
l = []
|
||||
def test_1(fix1):
|
||||
l.append(fix1)
|
||||
def test_2(fix1):
|
||||
l.append(fix1)
|
||||
def test_3():
|
||||
assert l[0] != l[1]
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines("""
|
||||
*ERROR*teardown*test_1*
|
||||
*KeyError*
|
||||
*ERROR*teardown*test_2*
|
||||
*KeyError*
|
||||
*3 pass*2 error*
|
||||
""")
|
||||
|
||||
|
||||
|
||||
def test_setupfunc_missing_funcarg(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
|
|
Loading…
Reference in New Issue