Skip to content

gh-143959: Fix test_datetime if _datetime is unavailable#145248

Open
serhiy-storchaka wants to merge 1 commit intopython:mainfrom
serhiy-storchaka:test_datetime-no-_datetime
Open

gh-143959: Fix test_datetime if _datetime is unavailable#145248
serhiy-storchaka wants to merge 1 commit intopython:mainfrom
serhiy-storchaka:test_datetime-no-_datetime

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Feb 26, 2026

@serhiy-storchaka serhiy-storchaka force-pushed the test_datetime-no-_datetime branch from 6c63822 to 519b99e Compare February 26, 2026 10:27
@vstinner
Copy link
Member

vstinner commented Mar 2, 2026

I tested this change with this local patch:

diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 005187f13e6..013816e99b3 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -4,6 +4,7 @@
 
 from test.support.import_helper import import_fresh_module
 
+sys.modules['_datetime'] = None
 
 TESTS = 'test.datetimetester'
 

On the main branch, test_datetime fails with:

test test_datetime crashed -- Traceback (most recent call last):
  File "/home/vstinner/python/main/Lib/test/libregrtest/single.py", line 210, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/vstinner/python/main/Lib/test/libregrtest/single.py", line 165, in _load_run_test
    regrtest_runner(result, test_func, runtests)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vstinner/python/main/Lib/test/libregrtest/single.py", line 118, in regrtest_runner
    test_result = test_func()
  File "/home/vstinner/python/main/Lib/test/libregrtest/single.py", line 162, in test_func
    return run_unittest(test_mod, runtests)
  File "/home/vstinner/python/main/Lib/test/libregrtest/single.py", line 38, in run_unittest
    raise Exception("errors while loading tests")
Exception: errors while loading tests

With this PR, test_datetime pass.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants