From a7c235732a10ac94f5c0881de49419d234fe2caf Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 20 Aug 2019 11:43:29 +0300 Subject: [PATCH] Pypy doesn't have sys.getrefcount(), so go back to gc --- testing/python/raises.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/python/raises.py b/testing/python/raises.py index 2b7e926159d..4607ef32768 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -159,6 +159,7 @@ def test_raises_cyclic_reference(self, method): """ Ensure pytest.raises does not leave a reference cycle (#1965). """ + import gc class T: def __call__(self): @@ -170,7 +171,7 @@ def __call__(self): raise ValueError t = T() - refcount = sys.getrefcount(t) + refcount = len(gc.get_referrers(t)) if method == "function": pytest.raises(ValueError, t) @@ -181,7 +182,7 @@ def __call__(self): # ensure both forms of pytest.raises don't leave exceptions in sys.exc_info() assert sys.exc_info() == (None, None, None) - assert sys.getrefcount(t) == refcount + assert refcount == len(gc.get_referrers(t)) def test_raises_match(self): msg = r"with base \d+"