summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index f1088ebb5..9144138d1 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -205,12 +205,21 @@ class TestSavezLoad(RoundtripTest, TestCase):
fp = open(tmp, 'wb')
np.savez(fp, data='LOVELY LOAD')
fp.close()
-
- for i in range(1, 1025):
- try:
- np.load(tmp)["data"]
- except Exception as e:
- raise AssertionError("Failed to load data from a file: %s" % e)
+ # We need to check if the garbage collector can properly close
+ # numpy npz file returned by np.load when their reference count
+ # goes to zero. Python 3 running in debug mode raises a
+ # ResourceWarning when file closing is left to the garbage
+ # collector, so we catch the warnings. Because ResourceWarning
+ # is unknown in Python < 3.x, we take the easy way out and
+ # catch all warnings.
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ for i in range(1, 1025):
+ try:
+ np.load(tmp)["data"]
+ except Exception as e:
+ msg = "Failed to load data from a file: %s" % e
+ raise AssertionError(msg)
finally:
os.remove(tmp)