summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2015-10-28 00:53:58 -0700
committerNathaniel J. Smith <njs@pobox.com>2015-10-28 21:01:55 -0700
commit0befb0b3444804b8a212ef069c4c3f141d19750b (patch)
tree0ac76379aea26f43c58969b6f53a233dddaa9a05
parentc0e48cfbbdef9cca954b0c4edd0052e1ec8a30aa (diff)
downloadnumpy-0befb0b3444804b8a212ef069c4c3f141d19750b.tar.gz
TST: attempt to make test_load_refcount deterministic
Use a different strategy to detect whether np.load creates cycles. Fixes gh-6571, I hope.
-rw-r--r--numpy/lib/tests/test_io.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index f4ce67805..af904e96a 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1905,12 +1905,17 @@ def test_load_refcount():
np.savez(f, [1, 2, 3])
f.seek(0)
- gc.collect()
- n_before = len(gc.get_objects())
- np.load(f)
- n_after = len(gc.get_objects())
-
- assert_equal(n_before, n_after)
+ assert_(gc.isenabled())
+ gc.disable()
+ try:
+ gc.collect()
+ np.load(f)
+ # gc.collect returns the number of unreachable objects in cycles that
+ # were found -- we are checking that no cycles were created by np.load
+ n_objects_in_cycles = gc.collect()
+ finally:
+ gc.enable()
+ assert_equal(n_objects_in_cycles, 0)
if __name__ == "__main__":
run_module_suite()