diff --git a/test/test_gmail/test_gmail.py b/test/test_gmail/test_gmail.py index 35fc99277..d31d488b3 100644 --- a/test/test_gmail/test_gmail.py +++ b/test/test_gmail/test_gmail.py @@ -2,10 +2,10 @@ import json import os import requests_mock +import email import unittest import shutil import base64 -import email _dir = os.path.dirname(__file__) @@ -516,10 +516,27 @@ def test__validate_email_string(self): {"email": "", "expected": True}, {"email": "Sender sender@email.com", "expected": False}, {"email": "Sender ", "expected": False}, - {"email": "Sender ", "expected": True}, - {"email": "Sender ", "expected": True}, ] + # The behavior of email.parseaddr depends on the python patch version + # See https://github.com/python/cpython/issues/102988 + # or associated changelogs, e.g. + # https://docs.python.org/3.8/whatsnew/changelog.html#python-3-8-20-final + if getattr(email.utils, "supports_strict_parsing", False): + emails.extend( + [ + {"email": "Sender ", "expected": False}, + {"email": "Sender ", "expected": False}, + ] + ) + else: + emails.extend( + [ + {"email": "Sender ", "expected": True}, + {"email": "Sender ", "expected": True}, + ] + ) + for e in emails: if e["expected"]: self.assertTrue(self.gmail._validate_email_string(e["email"]))