[3.12] gh-126499: test_ssl: Don't assume err.reason is a string (GH-126501) (GH-126573)

gh-126499: test_ssl: Don't assume err.reason is a string (GH-126501)

The skipping machinery called `getattr(err, "reason", "")` on an arbitrary
exception. As intermittent Buildbot failures show, sometimes it's set
to None.

Convert it to string for this specific check.
(cherry picked from commit 78ad7e6322)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-11-11 13:56:08 +01:00 committed by GitHub
parent 75d251bb04
commit d62f100fe1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4817,7 +4817,7 @@ class TestPreHandshakeClose(unittest.TestCase):
return # Expect the full test setup to always work on Linux.
if (isinstance(err, ConnectionResetError) or
(isinstance(err, OSError) and err.errno == errno.EINVAL) or
re.search('wrong.version.number', getattr(err, "reason", ""), re.I)):
re.search('wrong.version.number', str(getattr(err, "reason", "")), re.I)):
# On Windows the TCP RST leads to a ConnectionResetError
# (ECONNRESET) which Linux doesn't appear to surface to userspace.
# If wrap_socket() winds up on the "if connected:" path and doing