pytz test failures with Python 3.8.0a2: PicklingTest.testDatabaseFixes fails
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pytz |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
With both pytz-2018.5 and pytz-2018.9 I get the following test failure with Python 3.8.0a2:
=======
_______
self = <test_tzinfo.
def testDatabaseFix
# Hack the pickle to make it refer to a timezone abbreviation
# that does not match anything. The unpickler should be able
# to repair this case
tz = pytz.timezone(
p = pickle.dumps(tz)
tzname = tz._tzname
hacked_p = p.replace(
)
# Simulate a database correction. In this case, the incorrect
# data will continue to be used.
p = pickle.dumps(tz)
# Python 3 introduced a new pickle protocol where numbers are stored in
# hexadecimal representation. Here we extract the pickle
# representation of the number for the current Python version.
hacked_p = p.replace(
> self.assertNotE
E AssertionError: b'\x80\
pytz/tests/
=============== 1 failed, 232 passed, 1 skipped in 1.61 seconds ================
Changed in pytz: | |
status: | Fix Committed → Fix Released |
The failing test inspect pickle binary data... I'm not sure of the purpose of the test.
Python 3.8 changed to default pickle protocol from 3 to 4, whereas pytz test is written for pickle protocol 3 (or protocol 0 on Python 2).
The following change fix the test on Python 3.8. I tested my change on Python 2.7, 3.7 and 3.8:
--- pytz/tests/ test_tzinfo. py.old 2019-03-14 15:02:49.694890849 +0100 test_tzinfo. py 2019-03-14 15:09:14.773704193 +0100 dumps(tz. _utcoffset. seconds) [3:-1] dumps(new_ utcoffset) [3:-1] dumps(tz. _utcoffset. seconds, protocol)[3:-1] dumps(new_ utcoffset, protocol)[3:-1] old_pickle_ pattern, new_pickle_pattern)
+++ pytz/tests/
@@ -183,8 +183,11 @@
# Python 3 introduced a new pickle protocol where numbers are stored in
# hexadecimal representation. Here we extract the pickle
# representation of the number for the current Python version.
- old_pickle_pattern = pickle.
- new_pickle_pattern = pickle.
+ #
+ # Test protocol 3 on Python 3 and protocol 0 on Python 2.
+ protocol = (3 if sys.version_info >= (3,) else 0)
+ old_pickle_pattern = pickle.
+ new_pickle_pattern = pickle.
hacked_p = p.replace(