From 8ca28acd0d121c778aa540c1d61f58f5ae2d5dcc Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 17 May 2022 23:24:32 -0700 Subject: [PATCH] Fix unit tests for Python 3.11. --- test/units/module_utils/urls/test_fetch_url.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/units/module_utils/urls/test_fetch_url.py b/test/units/module_utils/urls/test_fetch_url.py index 4869bb0f46b..94f2e1bc91c 100644 --- a/test/units/module_utils/urls/test_fetch_url.py +++ b/test/units/module_utils/urls/test_fetch_url.py @@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import socket +import sys from ansible.module_utils.six import StringIO from ansible.module_utils.six.moves.http_cookiejar import Cookie @@ -133,9 +134,16 @@ def test_fetch_url_cookies(mocker, fake_ansible_module): r, info = fetch_url(fake_ansible_module, 'http://ansible.com/') assert info['cookies'] == {'Baz': 'qux', 'Foo': 'bar'} - # Python sorts cookies in order of most specific (ie. longest) path first - # items with the same path are reversed from response order - assert info['cookies_string'] == 'Baz=qux; Foo=bar' + + if sys.version_info < (3, 11): + # Python sorts cookies in order of most specific (ie. longest) path first + # items with the same path are reversed from response order + assert info['cookies_string'] == 'Baz=qux; Foo=bar' + else: + # Python 3.11 and later preserve the Set-Cookie order. + # See: https://github.com/python/cpython/pull/22745/ + assert info['cookies_string'] == 'Foo=bar; Baz=qux' + # The key here has a `-` as opposed to what we see in the `uri` module that converts to `_` # Note: this is response order, which differs from cookies_string assert info['set-cookie'] == 'Foo=bar, Baz=qux'