[2.7] bpo-34068: iobase_close could call PyObject_SetAttrString with an exception set (GH-8282). (GH-8312) (GH-8314)
(cherry picked from commit 28f07364f066792ceee93231dbb80ae8ad98b2bb)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>.
(cherry picked from commit cc13016658a9ed86d0b702ab6c251ad5952a952f)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index ebaf796..26c5dfe 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -690,6 +690,16 @@
self.assertEqual(stream.readinto(buffer), 5)
self.assertEqual(buffer.tobytes(), b"12345")
+ def test_close_assert(self):
+ class R(self.IOBase):
+ def __setattr__(self, name, value):
+ pass
+ def flush(self):
+ raise OSError()
+ f = R()
+ # This would cause an assertion failure.
+ self.assertRaises(OSError, f.close)
+
class CIOTest(IOTest):