Skip to content

Commit aa53e37

Browse files
committed
Add a test to expose leaked PseudoFixtureDef types.
1 parent 75f11f0 commit aa53e37

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

testing/python/fixture.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,41 @@ def test_method(self, something):
519519
assert len(arg2fixturedefs) == 1
520520
assert arg2fixturedefs['something'][0].argname == "something"
521521

522+
def test_request_garbage(self, testdir):
523+
testdir.makepyfile("""
524+
import sys
525+
import pytest
526+
import gc
527+
528+
@pytest.fixture(autouse=True)
529+
def something(request):
530+
# this method of test doesn't work on pypy
531+
if hasattr(sys, "pypy_version_info"):
532+
yield
533+
else:
534+
original = gc.get_debug()
535+
gc.set_debug(gc.DEBUG_SAVEALL)
536+
gc.collect()
537+
538+
yield
539+
540+
gc.collect()
541+
leaked_types = sum(1 for _ in gc.garbage
542+
if 'PseudoFixtureDef' in str(_))
543+
544+
gc.garbage[:] = []
545+
546+
try:
547+
assert leaked_types == 0
548+
finally:
549+
gc.set_debug(original)
550+
551+
def test_func():
552+
pass
553+
""")
554+
reprec = testdir.inline_run()
555+
reprec.assertoutcome(passed=1)
556+
522557
def test_getfixturevalue_recursive(self, testdir):
523558
testdir.makeconftest("""
524559
import pytest

0 commit comments

Comments
 (0)