Add a test to expose leaked PseudoFixtureDef types.

This commit is contained in:
Allan Feldman 2018-02-21 21:35:35 -08:00
parent 75f11f0b65
commit aa53e37fa2
1 changed files with 35 additions and 0 deletions

View File

@ -519,6 +519,41 @@ class TestRequestBasic(object):
assert len(arg2fixturedefs) == 1
assert arg2fixturedefs['something'][0].argname == "something"
def test_request_garbage(self, testdir):
testdir.makepyfile("""
import sys
import pytest
import gc
@pytest.fixture(autouse=True)
def something(request):
# this method of test doesn't work on pypy
if hasattr(sys, "pypy_version_info"):
yield
else:
original = gc.get_debug()
gc.set_debug(gc.DEBUG_SAVEALL)
gc.collect()
yield
gc.collect()
leaked_types = sum(1 for _ in gc.garbage
if 'PseudoFixtureDef' in str(_))
gc.garbage[:] = []
try:
assert leaked_types == 0
finally:
gc.set_debug(original)
def test_func():
pass
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
def test_getfixturevalue_recursive(self, testdir):
testdir.makeconftest("""
import pytest