Skip to content

Commit

Permalink
TST: disable gc in refcount test (numpy#11158)
Browse files Browse the repository at this point in the history
The vectorize version of this test was failing consistently on several of the Appveyor builds, ever since a recent pytest upgrade.

Our theory is that by random chance, things changed so that during the call to vectorize(op).__call__, python started running a garbage collection, which perturbed the refcounts that this test is checking. (Specifically this test is doing a weird thing and checking that the refcount of the object 1 doesn't decrease, and it's very plausible that some random bit of garbage was holding a reference to this object.)

Disabling the gc during the test makes this kind of refcount assertion more reliable, and seems to have fixed the appveyor builds, so I guess it's good.
  • Loading branch information
mattip authored and njsmith committed May 25, 2018
1 parent 4d02fb1 commit 055620c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,16 +1373,20 @@ def _assert_valid_refcount(op):
"""
if not HAS_REFCOUNT:
return True
import numpy as np
import numpy as np, gc

b = np.arange(100*100).reshape(100, 100)
c = b
i = 1

rc = sys.getrefcount(i)
for j in range(15):
d = op(b, c)
assert_(sys.getrefcount(i) >= rc)
gc.disable()
try:
rc = sys.getrefcount(i)
for j in range(15):
d = op(b, c)
assert_(sys.getrefcount(i) >= rc)
finally:
gc.enable()
del d # for pyflakes


Expand Down

0 comments on commit 055620c

Please sign in to comment.