New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_datetime.test_strptime() random failures on "s390x SLES" buildbots #69355
Comments
It looks like the failure is random. It probably depends on the test order. http://buildbot.python.org/all/builders/s390x%20SLES%203.4/builds/45/steps/test/logs/stdio ====================================================================== Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/test/datetimetester.py", line 1941, in test_strptime
dt = strptime(dtstr, "%z %Z")
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/datetime.py", line 1607, in strptime
return _strptime._strptime_datetime(cls, date_string, format)
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data '-0500 EST' does not match format '%z %Z' ====================================================================== Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/test/datetimetester.py", line 1941, in test_strptime
dt = strptime(dtstr, "%z %Z")
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/datetime.py", line 1607, in strptime
return _strptime._strptime_datetime(cls, date_string, format)
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data '-0500 EST' does not match format '%z %Z' ====================================================================== Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/test/datetimetester.py", line 1941, in test_strptime
dt = strptime(dtstr, "%z %Z")
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/datetime.py", line 1607, in strptime
return _strptime._strptime_datetime(cls, date_string, format)
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/home/dje/cpython-buildarea/3.4.edelsohn-sles-z/build/Lib/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data '-0500 EST' does not match format '%z %Z' |
I wonder if this has anything to do with _strptime._TimeRE_cache. This seems to get initialized when _strptime is first imported. Some of the tests in datetimetester temporarily set the timezone to -0500 EST, and another to UTC, but they change it back afterwards. So I cannot see how it could have an effect, but I don’t have a better theory. >>> import _strptime # Regular expression cache is initialized
>>> _strptime._TimeRE_cache["Z"] # I don't have a time zone set
'(?P<Z>gmt|utc)'
>>> import os, time
>>> os.environ["TZ"] = 'EST+05EDT,M3.2.0,M11.1.0'
>>> time.tzset()
>>> time.tzname
('EST', 'EDT')
>>> from datetime import datetime
>>> datetime.strptime("-0500 EST", "%z %Z") # Using original cache
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/proj/python/cpython/Lib/_strptime.py", line 555, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/home/proj/python/cpython/Lib/_strptime.py", line 356, in _strptime
(data_string, format))
ValueError: time data '-0500 EST' does not match format '%z %Z' |
New changeset 139c18943d9b by Martin Panter in branch 'default': |
Info when the s390x SLES 3.x buildbot failed <http://buildbot.python.org/all/builders/s390x%20SLES%203.x/builds/414/steps/test/logs/stdio\>: _TimeRE_cache['Z']='(?P<Z>std|utc|gmt|dst)' So it seems _TimeRE_cache has been initialized when time.tzname = ("STD", "DST"), and this agrees with the contents of _regex_cache. When the tests fail, there is no TZ environment variable set, but the test is trying to use the time zone “EST”, which apparently comes from time.tzname[0]. The question in my mind is why did tzname change from when _strptime was initialized to when the tests ran? Keys in _regex_cache, showing what has been parsed since it was cleared: '%Y-%m-%d %H:%M:%S.%f' test_strptime() is inherited by various classes. The first version passed, and the other five failed: test_strptime (test.datetimetester.TestDateTime) ... ok Inbetween the good and the first bad test_strptime() runs, there are the remaining TestDateTime tests, then the TestDateOnly, TestTZInfo, TestTimeZone, TestTimeTZ, TestDate, TestTimezoneConversions and TestTime classes, and finally the initial TestSubclassDateTime tests. Tests appear to be in alphabetical order by method name within each class, but the classes are in arbitrary order. |
Thanks to Martin's research I have wrote a patch that resets a cache when timezone is changed. Martin's example in msg254643 works with this patch. |
I just discovered bpo-20220 about a similar story with a tarfile test case. It looks like this is caused by the same underlying C library quirk, so I am closing this as a duplicate. Using Antoine’s reproducer there I triggered both this datetime failure and the tarfile failure: TZ='America/New_York' ./python -m test -v test_imaplib test_tarfile test_datetime Also Serhiy I discovered bpo-6478 about the strptime() cache which has patches trying to do a similar thing to your patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: