From d4413dac083426de6fd08f48b3fba2e6d5bcc5af Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 7 May 2021 16:41:32 -0700 Subject: [PATCH] Fix unit tests on Python 3.10. --- .../module_utils/basic/test_exit_json.py | 2 ++ test/units/parsing/vault/test_vault.py | 23 +++++++++++-------- test/units/requirements.txt | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/test/units/module_utils/basic/test_exit_json.py b/test/units/module_utils/basic/test_exit_json.py index 25b41450695..4afcb2761ce 100644 --- a/test/units/module_utils/basic/test_exit_json.py +++ b/test/units/module_utils/basic/test_exit_json.py @@ -104,6 +104,8 @@ class TestAnsibleModuleExitJson: if sys.version_info < (3,): error_msg = "fail_json() takes exactly 2 arguments (1 given)" + elif sys.version_info >= (3, 10): + error_msg = "AnsibleModule.fail_json() missing 1 required positional argument: 'msg'" else: error_msg = "fail_json() missing 1 required positional argument: 'msg'" diff --git a/test/units/parsing/vault/test_vault.py b/test/units/parsing/vault/test_vault.py index a9c4fc9ea39..ea04572a2f4 100644 --- a/test/units/parsing/vault/test_vault.py +++ b/test/units/parsing/vault/test_vault.py @@ -543,18 +543,21 @@ class TestVaultCipherAes256(unittest.TestCase): self.assertIsInstance(b_key_2, six.binary_type) self.assertEqual(b_key_1, b_key_2) - # And again with pycrypto - b_key_3 = self.vault_cipher._create_key_pycrypto(b_password, b_salt, key_length=32, iv_length=16) - self.assertIsInstance(b_key_3, six.binary_type) + if vault.HAS_PYCRYPTO: + # And again with pycrypto + b_key_3 = self.vault_cipher._create_key_pycrypto(b_password, b_salt, key_length=32, iv_length=16) + self.assertIsInstance(b_key_3, six.binary_type) - # verify we get the same answer - # we could potentially run a few iterations of this and time it to see if it's roughly constant time - # and or that it exceeds some minimal time, but that would likely cause unreliable fails, esp in CI - b_key_4 = self.vault_cipher._create_key_pycrypto(b_password, b_salt, key_length=32, iv_length=16) - self.assertIsInstance(b_key_4, six.binary_type) - self.assertEqual(b_key_3, b_key_4) - self.assertEqual(b_key_1, b_key_4) + # verify we get the same answer + # we could potentially run a few iterations of this and time it to see if it's roughly constant time + # and or that it exceeds some minimal time, but that would likely cause unreliable fails, esp in CI + b_key_4 = self.vault_cipher._create_key_pycrypto(b_password, b_salt, key_length=32, iv_length=16) + self.assertIsInstance(b_key_4, six.binary_type) + self.assertEqual(b_key_3, b_key_4) + self.assertEqual(b_key_1, b_key_4) + @pytest.mark.skipif(not vault.HAS_PYCRYPTO, + reason='PyCrypto is not installed') def test_create_key_known_pycrypto(self): b_password = b'hunter42' diff --git a/test/units/requirements.txt b/test/units/requirements.txt index 153500e35b3..5a68052eedc 100644 --- a/test/units/requirements.txt +++ b/test/units/requirements.txt @@ -1,4 +1,4 @@ -pycrypto +pycrypto ; python_version < '3.10' # pycrypto is not compatible with Python 3.10 passlib pywinrm pytz