Add workaround for test_raises_cyclic_reference in Python 3.5.{0,1}

This commit is contained in:
Ran Benita 2019-08-20 11:19:25 +03:00
parent a7ede64f42
commit cec2183aeb
1 changed files with 8 additions and 9 deletions

View File

@ -159,13 +159,19 @@ class TestRaises:
"""
Ensure pytest.raises does not leave a reference cycle (#1965).
"""
import gc
class T:
def __call__(self):
# Early versions of Python 3.5 have some bug causing the
# __call__ frame to still refer to t even after everything
# is done. This makes the test pass for them.
if sys.version_info < (3, 5, 2):
del self
raise ValueError
t = T()
refcount = sys.getrefcount(t)
if method == "function":
pytest.raises(ValueError, t)
else:
@ -175,14 +181,7 @@ class TestRaises:
# ensure both forms of pytest.raises don't leave exceptions in sys.exc_info()
assert sys.exc_info() == (None, None, None)
del t
# Make sure this does get updated in locals dict
# otherwise it could keep a reference
locals()
# ensure the t instance is not stuck in a cyclic reference
for o in gc.get_objects():
assert type(o) is not T
assert sys.getrefcount(t) == refcount
def test_raises_match(self):
msg = r"with base \d+"