Skip to content

Commit

Permalink
Add workaround for test_raises_cyclic_reference in Python 3.5.{0,1}
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Aug 20, 2019
1 parent a7ede64 commit cec2183
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions testing/python/raises.py
Expand Up @@ -159,13 +159,19 @@ def test_raises_cyclic_reference(self, method):
"""
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:
Expand All @@ -175,14 +181,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)

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+"
Expand Down

0 comments on commit cec2183

Please sign in to comment.