From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sun, 22 Mar 2026 14:39:08 +0000 (+0100) Subject: [3.13] gh-143959: Fix test_datetime if _datetime is unavailable (GH-145248) (GH-146289) X-Git-Tag: v3.13.13~68 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0aa9153cf7c70cb47cb0f51b901e42d428f0b338;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-143959: Fix test_datetime if _datetime is unavailable (GH-145248) (GH-146289) (cherry picked from commit 97c725cd391ac63a934a6fe6f97602fe4c56f473) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 22ab655507a6..6749fad35a64 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -49,7 +49,11 @@ import _strptime try: import _pydatetime except ImportError: - pass + _pydatetime = None +try: + import _datetime +except ImportError: + _datetime = None # pickle_loads = {pickle.loads, pickle._loads} diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index 005187f13e66..137c8d2686c2 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -18,16 +18,19 @@ def load_tests(loader, tests, pattern): finally: # XXX: import_fresh_module() is supposed to leave sys.module cache untouched, # XXX: but it does not, so we have to cleanup ourselves. - for modname in ['datetime', '_datetime', '_strptime']: + for modname in ['datetime', '_datetime', '_pydatetime', '_strptime']: sys.modules.pop(modname, None) test_modules = [pure_tests, fast_tests] test_suffixes = ["_Pure", "_Fast"] + # XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might # not believe this, but in spite of all the sys.modules trickery running a _Pure # test last will leave a mix of pure and native datetime stuff lying around. for module, suffix in zip(test_modules, test_suffixes): test_classes = [] + if module is None: + continue for name, cls in module.__dict__.items(): if not isinstance(cls, type): continue @@ -48,8 +51,8 @@ def load_tests(loader, tests, pattern): cls_._save_sys_modules = sys.modules.copy() sys.modules[TESTS] = module sys.modules['datetime'] = module.datetime_module - if hasattr(module, '_pydatetime'): - sys.modules['_pydatetime'] = module._pydatetime + sys.modules['_pydatetime'] = module._pydatetime + sys.modules['_datetime'] = module._datetime sys.modules['_strptime'] = module._strptime super().setUpClass()