classification
Title: Running test_datetime twice fails with: module 'datetime' has no attribute '_divide_and_round'
Type: Stage: patch review
Components: Tests Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, corona10, georg.brandl, p-ganssle, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2020-03-25 01:54 by vstinner, last changed 2020-03-29 08:58 by shihai1991.

Pull Requests
URL Status Linked Edit
PR 19213 open shihai1991, 2020-03-29 08:47
Messages (6)
msg364970 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-25 01:54
vstinner@apu$ ./python -m test -v test_datetime test_datetime -m test_divide_and_round
== CPython 3.9.0a5+ (heads/pr/19122:0ac3031a80, Mar 25 2020, 02:25:19) [GCC 9.2.1 20190827 (Red Hat 9.2.1-1)]
== Linux-5.5.9-200.fc31.x86_64-x86_64-with-glibc2.30 little-endian
== cwd: /home/vstinner/python/master/build/test_python_233006
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
0:00:00 load avg: 0.82 Run tests sequentially
0:00:00 load avg: 0.82 [1/2] test_datetime
test_divide_and_round (test.datetimetester.TestModule_Pure) ... ok
test_divide_and_round (test.datetimetester.TestModule_Fast) ... skipped 'Only run for Pure Python implementation'

----------------------------------------------------------------------

Ran 2 tests in 0.002s

OK (skipped=1)
0:00:00 load avg: 0.82 [2/2] test_datetime
test_divide_and_round (test.datetimetester.TestModule_Pure) ... ERROR
test_divide_and_round (test.datetimetester.TestModule_Fast) ... skipped 'Only run for Pure Python implementation'

======================================================================
ERROR: test_divide_and_round (test.datetimetester.TestModule_Pure)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/test/datetimetester.py", line 87, in test_divide_and_round
    dar = datetime_module._divide_and_round
AttributeError: module 'datetime' has no attribute '_divide_and_round'

----------------------------------------------------------------------

Ran 2 tests in 0.006s

FAILED (errors=1, skipped=1)
test test_datetime failed
test_datetime failed

== Tests result: FAILURE ==

1 test OK.

1 test failed:
    test_datetime

Total duration: 448 ms
Tests result: FAILURE
msg364993 - (view) Author: hai shi (shihai1991) * Date: 2020-03-25 15:52
`_divide_and_round()` would be deleted in https://github.com/python/cpython/blob/master/Lib/datetime.py#L2516.

if it's removed L2516 of datetime.py, `test_name_cleanup()` would be failed.Looks like it's a planed behavior~
msg365012 - (view) Author: hai shi (shihai1991) * Date: 2020-03-25 18:54
add a pdb point in L11 of test_datetime.py

  8     try:
  9         pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
 10                                          blocked=['_datetime'])
 11         import pdb;pdb.set_trace()
 12  ->     fast_tests = import_fresh_module(TESTS, fresh=['datetime',
 13                                                        '_datetime', '_strptime'])

and run `./python -m test test_datetime test_datetime`:
the first iteration:
(Pdb) pure_tests.datetime_module._divide_and_round
<function _divide_and_round at 0x7f694df8e7e0>
the second iteration(`_datetime` not blocked?):
(Pdb) pure_tests.datetime_module._divide_and_round
*** AttributeError: module 'datetime' has no attribute '_divide_and_round'
msg365018 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2020-03-25 19:46
This isn't exactly "working as intended", but I believe it's a known problem with either `import_fresh_module` or `datetime`, as you can see from these comments: https://github.com/python/cpython/blob/302e5a8f79514fd84bafbc44b7c97ec636302322/Lib/test/test_datetime.py#L14-L23

Based on the git blame, those TODO comments are from Georg Brandl, so I'm adding him to the nosy list in case he has some insight.
msg365020 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2020-03-25 19:59
Sorry, it seems that was far too long ago for me to remember anything :)
msg365248 - (view) Author: hai shi (shihai1991) * Date: 2020-03-29 08:58
> I believe it's a known problem with either `import_fresh_module` or `datetime`
after removed the cleanup operation of `sys.modules` in PR19213, the  testcases is successed in my local vm(I am not sure there have any other potential risks).
History
Date User Action Args
2020-03-29 08:58:40shihai1991setmessages: + msg365248
2020-03-29 08:47:39shihai1991setkeywords: + patch
stage: patch review
pull_requests: + pull_request18576
2020-03-25 19:59:50georg.brandlsetmessages: + msg365020
2020-03-25 19:46:14p-gansslesetnosy: + georg.brandl
messages: + msg365018
2020-03-25 18:54:40shihai1991setmessages: + msg365012
2020-03-25 15:52:39shihai1991setnosy: + shihai1991
messages: + msg364993
2020-03-25 15:44:41xtreaksetnosy: + belopolsky, p-ganssle
2020-03-25 15:42:13corona10setnosy: + corona10
2020-03-25 01:54:40vstinnercreate