From f417f5398e4df1ef79c6c3835368f72b39a08af7 Mon Sep 17 00:00:00 2001 From: Stuart Bishop Date: Wed, 31 Jul 2019 15:15:17 +0000 Subject: Use explicit pickle protocol versions in tests Addresses lp:1819751 using fix by Victor Stinner --- src/pytz/tests/test_tzinfo.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pytz/tests/test_tzinfo.py b/src/pytz/tests/test_tzinfo.py index e56fef5..85aae12 100644 --- a/src/pytz/tests/test_tzinfo.py +++ b/src/pytz/tests/test_tzinfo.py @@ -183,8 +183,14 @@ class PicklingTest(unittest.TestCase): # 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.dumps(tz._utcoffset.seconds)[3:-1] - new_pickle_pattern = pickle.dumps(new_utcoffset)[3:-1] + # + # Test protocol 3 on Python 3 and protocol 0 on Python 2. + if sys.version_info >= (3,): + protocol = 3 + else: + protocol = 0 + old_pickle_pattern = pickle.dumps(tz._utcoffset.seconds, protocol)[3:-1] + new_pickle_pattern = pickle.dumps(new_utcoffset, protocol)[3:-1] hacked_p = p.replace(old_pickle_pattern, new_pickle_pattern) self.assertNotEqual(p, hacked_p) -- cgit v1.2.1