Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85ec8d9

Browse files
committed
Merge pull request numpy#6576 from njsmith/test_load_refcount-fix
TST: attempt to make test_load_refcount deterministic
2 parents 8b4904e + 0befb0b commit 85ec8d9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

numpy/lib/tests/test_io.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,12 +1905,17 @@ def test_load_refcount():
19051905
np.savez(f, [1, 2, 3])
19061906
f.seek(0)
19071907

1908-
gc.collect()
1909-
n_before = len(gc.get_objects())
1910-
np.load(f)
1911-
n_after = len(gc.get_objects())
1912-
1913-
assert_equal(n_before, n_after)
1908+
assert_(gc.isenabled())
1909+
gc.disable()
1910+
try:
1911+
gc.collect()
1912+
np.load(f)
1913+
# gc.collect returns the number of unreachable objects in cycles that
1914+
# were found -- we are checking that no cycles were created by np.load
1915+
n_objects_in_cycles = gc.collect()
1916+
finally:
1917+
gc.enable()
1918+
assert_equal(n_objects_in_cycles, 0)
19141919

19151920
if __name__ == "__main__":
19161921
run_module_suite()

0 commit comments

Comments
 (0)