summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2018-05-25 02:54:02 +0200
committerNathaniel J. Smith <njs@pobox.com>2018-05-24 17:54:02 -0700
commit055620ccd669ea56d83391e107a467824cd5b60b (patch)
tree26d8442e343abbc37e4e2b26538d2521e7e5dac3 /numpy/testing/_private/utils.py
parent4d02fb11352a45b05e5d50db6e71153b2aec7527 (diff)
downloadnumpy-055620ccd669ea56d83391e107a467824cd5b60b.tar.gz
TST: disable gc in refcount test (#11158)
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.
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index c420e1fb5..a7935f175 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -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