bpo-18748: test_io: silence destructor errors
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 811a446f92be31..5406a2891bb251 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -991,6 +991,9 @@ def flush(self):
         # This would cause an assertion failure.
         self.assertRaises(OSError, f.close)
 
+        # Silence destructor error
+        R.flush = lambda self: None
+
 
 class CIOTest(IOTest):
 
@@ -1167,6 +1170,10 @@ def bad_close():
         self.assertEqual(err.exception.__context__.args, ('flush',))
         self.assertFalse(b.closed)
 
+        # Silence destructor error
+        raw.close = lambda: None
+        b.flush = lambda: None
+
     def test_nonnormalized_close_error_on_close(self):
         # Issue #21677
         raw = self.MockRawIO()
@@ -1184,6 +1191,10 @@ def bad_close():
         self.assertIn('non_existing_flush', str(err.exception.__context__))
         self.assertFalse(b.closed)
 
+        # Silence destructor error
+        b.flush = lambda: None
+        raw.close = lambda: None
+
     def test_multi_close(self):
         raw = self.MockRawIO()
         b = self.tp(raw)
@@ -2039,6 +2050,9 @@ def reader_close():
         self.assertFalse(reader.closed)
         self.assertTrue(writer.closed)
 
+        # Silence destructor error
+        reader.close = lambda: None
+
     def test_writer_close_error_on_close(self):
         def writer_close():
             writer_non_existing
@@ -2053,6 +2067,9 @@ def writer_close():
         self.assertTrue(reader.closed)
         self.assertFalse(writer.closed)
 
+        # Silence destructor error
+        writer.close = lambda: None
+
     def test_reader_writer_close_error_on_close(self):
         def reader_close():
             reader_non_existing
@@ -2072,6 +2089,10 @@ def writer_close():
         self.assertFalse(reader.closed)
         self.assertFalse(writer.closed)
 
+        # Silence destructor error
+        reader.close = lambda: None
+        writer.close = lambda: None
+
     def test_isatty(self):
         class SelectableIsAtty(MockRawIO):
             def __init__(self, isatty):
@@ -3270,6 +3291,10 @@ def bad_close():
         self.assertEqual(err.exception.__context__.args, ('flush',))
         self.assertFalse(txt.closed)
 
+        # Silence destructor error
+        buffer.close = lambda: None
+        txt.flush = lambda: None
+
     def test_nonnormalized_close_error_on_close(self):
         # Issue #21677
         buffer = self.BytesIO(self.testdata)
@@ -3287,6 +3312,10 @@ def bad_close():
         self.assertIn('non_existing_flush', str(err.exception.__context__))
         self.assertFalse(txt.closed)
 
+        # Silence destructor error
+        buffer.close = lambda: None
+        txt.flush = lambda: None
+
     def test_multi_close(self):
         txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
         txt.close()



<!-- issue-number: [bpo-18748](https://bugs.python.org/issue18748) -->
https://bugs.python.org/issue18748
<!-- /issue-number -->
