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'