From cec2183aebe8106f740b2891422d5818dd01a399 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 20 Aug 2019 11:19:25 +0300 Subject: [PATCH] Add workaround for test_raises_cyclic_reference in Python 3.5.{0,1} --- testing/python/raises.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/testing/python/raises.py b/testing/python/raises.py index 668be57fc..2b7e92615 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -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+"