Fix #11513: wrong exception handling for the case that GzipFile itself raises an IOError.
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 8036c5c..b45f168 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1682,6 +1682,14 @@
class GzipMiscReadTest(MiscReadTest):
tarname = gzipname
mode = "r:gz"
+
+ def test_non_existent_targz_file(self):
+ # Test for issue11513: prevent non-existent gzipped tarfiles raising
+ # multiple exceptions.
+ with self.assertRaisesRegex(IOError, "xxx") as ex:
+ tarfile.open("xxx", self.mode)
+ self.assertEqual(ex.exception.errno, errno.ENOENT)
+
class GzipUstarReadTest(UstarReadTest):
tarname = gzipname
mode = "r:gz"