diff --git a/bob/io/base/test_hdf5.py b/bob/io/base/test_hdf5.py
index 91ffb30e51872410cfc230db017e120b6393b7a0..dfd2da2a9efaeecf84198745876deacc85b39d82 100644
--- a/bob/io/base/test_hdf5.py
+++ b/bob/io/base/test_hdf5.py
@@ -420,14 +420,17 @@ def test_close():
     outfile = HDF5File(tmpname, 'w')
     outfile.close()
 
-    with nose.tools.assert_raises(RuntimeError):
+    def test_set():
       outfile.set("Test", numpy.array([1,2]))
+    nose.tools.assert_raises(RuntimeError, test_set)
 
-    with nose.tools.assert_raises(RuntimeError):
+    def test_read():
       test = outfile.read("Test")
+    nose.tools.assert_raises(RuntimeError, test_read)
 
-    with nose.tools.assert_raises(RuntimeError):
-      outfile.filename
+    def test_filename():
+      fn = outfile.filename
+    nose.tools.assert_raises(RuntimeError, test_filename)
 
   finally:
     os.unlink(tmpname)