[Pytest-commit] Issue #498: Function scope fixture with failing finalizer called only once (hpk42/pytest)
Alexander Steinert
issues-reply at bitbucket.org
Thu Apr 3 14:56:37 CEST 2014
New issue 498: Function scope fixture with failing finalizer called only once
https://bitbucket.org/hpk42/pytest/issue/498/function-scope-fixture-with-failing
Alexander Steinert:
``` python
import pytest
class Helper:
pass
@pytest.fixture(scope="function")
def failing_fixture(request):
helper = Helper()
def fin():
raise RuntimeError("On purpose!")
request.addfinalizer(fin)
return helper
def test_0(failing_fixture):
print("test_0", failing_fixture)
def test_1(failing_fixture):
# In pytest 2.3.5 and 2.5.2, this test gets the same helper instance like
# test_0 and the fixture's finalizer is not called.
print("test_1", failing_fixture)
assert 0
```
```
============================= test session starts ==============================
platform linux2 -- Python 3.2.3 -- py-1.4.20 -- pytest-2.5.2
collected 2 items
test_pytest.py .EF
==================================== ERRORS ====================================
_________________________ ERROR at teardown of test_0 __________________________
def fin():
> raise RuntimeError("On purpose!")
E RuntimeError: On purpose!
test_pytest.py:12: RuntimeError
------------------------------- Captured stdout --------------------------------
test_0 <test_pytest.Helper object at 0x1be0710>
=================================== FAILURES ===================================
____________________________________ test_1 ____________________________________
failing_fixture = <test_pytest.Helper object at 0x1be0710>
def test_1(failing_fixture):
# In pytest 2.3.5 and 2.5.2, this test gets the same helper instance like
# test_0 and the fixture's finalizer is not called.
print("test_1", failing_fixture)
> assert 0
E assert 0
test_pytest.py:25: AssertionError
------------------------------- Captured stdout --------------------------------
test_1 <test_pytest.Helper object at 0x1be0710>
================= 1 failed, 1 passed, 1 error in 0.03 seconds ==================
```
More information about the pytest-commit
mailing list