From db50a975fd2377e28bafd82edbd90bc2e9aeeb1b Mon Sep 17 00:00:00 2001 From: Victor Maryama Date: Tue, 25 Jun 2019 17:23:14 +0200 Subject: [PATCH] Reverted leak fixture test. --- testing/acceptance_test.py | 45 ++++++++++++++++++++++++ testing/fixture_values_leak_test.py | 53 ----------------------------- 2 files changed, 45 insertions(+), 53 deletions(-) delete mode 100644 testing/fixture_values_leak_test.py diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index ccb69dd79..60cc21c4a 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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 """ diff --git a/testing/fixture_values_leak_test.py b/testing/fixture_values_leak_test.py deleted file mode 100644 index 6f4c90d3e..000000000 --- a/testing/fixture_values_leak_test.py +++ /dev/null @@ -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 - -, - '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