Reverted leak fixture test.

This commit is contained in:
Victor Maryama 2019-06-25 17:23:14 +02:00
parent 81e3f3cf95
commit db50a975fd
2 changed files with 45 additions and 53 deletions

View File

@ -1047,6 +1047,51 @@ def test_deferred_hook_checking(testdir):
result.stdout.fnmatch_lines(["* 1 passed *"])
def test_fixture_values_leak(testdir):
"""Ensure that fixture objects are properly destroyed by the garbage collector at the end of their expected
life-times (#2981).
"""
testdir.makepyfile(
"""
import attr
import gc
import pytest
import weakref
@attr.s
class SomeObj(object):
name = attr.ib()
fix_of_test1_ref = None
session_ref = None
@pytest.fixture(scope='session')
def session_fix():
global session_ref
obj = SomeObj(name='session-fixture')
session_ref = weakref.ref(obj)
return obj
@pytest.fixture
def fix(session_fix):
global fix_of_test1_ref
obj = SomeObj(name='local-fixture')
fix_of_test1_ref = weakref.ref(obj)
return obj
def test1(fix):
assert fix_of_test1_ref() is fix
def test2():
gc.collect()
# fixture "fix" created during test1 must have been destroyed by now
assert fix_of_test1_ref() is None
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["* 2 passed *"])
def test_fixture_order_respects_scope(testdir):
"""Ensure that fixtures are created according to scope order, regression test for #2405
"""

View File

@ -1,53 +0,0 @@
"""Ensure that fixture objects are properly destroyed by the garbage collector at the end of their expected
life-times (#2981).
This comes from the old acceptance_test.py::test_fixture_values_leak(testdir):
This used pytester before but was not working when using pytest_assert_reprcompare
because pytester tracks hook calls and it would hold a reference (ParsedCall object),
preventing garbage collection
<ParsedCall 'pytest_assertrepr_compare'(**{
'config': <_pytest.config.Config object at 0x0000019C18D1C2B0>,
'op': 'is',
'left': SomeObj(name='local-fixture'),
'right': SomeObj(name='local-fixture')})>
"""
import attr
import gc
import pytest
import weakref
@attr.s
class SomeObj(object):
name = attr.ib()
fix_of_test1_ref = None
session_ref = None
@pytest.fixture(scope="session")
def session_fix():
global session_ref
obj = SomeObj(name="session-fixture")
session_ref = weakref.ref(obj)
return obj
@pytest.fixture
def fix(session_fix):
global fix_of_test1_ref
obj = SomeObj(name="local-fixture")
fix_of_test1_ref = weakref.ref(obj)
return obj
def test1(fix):
assert fix_of_test1_ref() is fix
def test2():
gc.collect()
# fixture "fix" created during test1 must have been destroyed by now
assert fix_of_test1_ref() is None