Change flaky test_request_garbage to provide more debug information
This test fails *very* rarely when running in xdist.
This commit is contained in:
parent
9aa6b0903b
commit
87ddb2dbd5
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -488,6 +489,10 @@ class TestRequestBasic(object):
|
||||||
assert len(arg2fixturedefs) == 1
|
assert len(arg2fixturedefs) == 1
|
||||||
assert arg2fixturedefs["something"][0].argname == "something"
|
assert arg2fixturedefs["something"][0].argname == "something"
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
hasattr(sys, "pypy_version_info"),
|
||||||
|
reason="this method of test doesn't work on pypy",
|
||||||
|
)
|
||||||
def test_request_garbage(self, testdir):
|
def test_request_garbage(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
@ -498,23 +503,22 @@ class TestRequestBasic(object):
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def something(request):
|
def something(request):
|
||||||
# this method of test doesn't work on pypy
|
|
||||||
if hasattr(sys, "pypy_version_info"):
|
|
||||||
yield
|
|
||||||
else:
|
|
||||||
original = gc.get_debug()
|
original = gc.get_debug()
|
||||||
gc.set_debug(gc.DEBUG_SAVEALL)
|
gc.set_debug(gc.DEBUG_SAVEALL)
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
try:
|
||||||
gc.collect()
|
gc.collect()
|
||||||
leaked_types = sum(1 for _ in gc.garbage
|
leaked_types = sum(1 for _ in gc.garbage
|
||||||
if isinstance(_, PseudoFixtureDef))
|
if isinstance(_, PseudoFixtureDef))
|
||||||
|
|
||||||
|
# debug leaked types if the test fails
|
||||||
|
print(leaked_types)
|
||||||
|
|
||||||
gc.garbage[:] = []
|
gc.garbage[:] = []
|
||||||
|
|
||||||
try:
|
|
||||||
assert leaked_types == 0
|
assert leaked_types == 0
|
||||||
finally:
|
finally:
|
||||||
gc.set_debug(original)
|
gc.set_debug(original)
|
||||||
|
@ -523,8 +527,8 @@ class TestRequestBasic(object):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reprec = testdir.inline_run()
|
result = testdir.runpytest()
|
||||||
reprec.assertoutcome(passed=1)
|
result.stdout.fnmatch_lines("* 1 passed in *")
|
||||||
|
|
||||||
def test_getfixturevalue_recursive(self, testdir):
|
def test_getfixturevalue_recursive(self, testdir):
|
||||||
testdir.makeconftest(
|
testdir.makeconftest(
|
||||||
|
|
Loading…
Reference in New Issue