diff --git a/tests/__init__.py b/tests/__init__.py index 31d4c018b3cb..4bfba60a8499 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -327,6 +327,10 @@ def __repr__(self): def requires_crt(reason=None): + if callable(reason): + raise TypeError( + "Use @requires_crt() with parentheses, not bare @requires_crt" + ) if reason is None: reason = "Test requires awscrt to be installed" diff --git a/tests/functional/s3/test_cp_command.py b/tests/functional/s3/test_cp_command.py index 507d133a32e2..d0243d657bd6 100644 --- a/tests/functional/s3/test_cp_command.py +++ b/tests/functional/s3/test_cp_command.py @@ -735,7 +735,7 @@ def test_upload_with_checksum_algorithm_crc32(self): self.assertEqual(self.operations_called[0][0].name, 'PutObject') self.assertEqual(self.operations_called[0][1]['ChecksumAlgorithm'], 'CRC32') - @requires_crt + @requires_crt() def test_upload_with_checksum_algorithm_crc32c(self): full_path = self.files.create_file('foo.txt', 'contents') cmdline = f'{self.prefix} {full_path} s3://bucket/key.txt --checksum-algorithm CRC32C' @@ -743,7 +743,7 @@ def test_upload_with_checksum_algorithm_crc32c(self): self.assertEqual(self.operations_called[0][0].name, 'PutObject') self.assertEqual(self.operations_called[0][1]['ChecksumAlgorithm'], 'CRC32C') - @requires_crt + @requires_crt() def test_upload_with_checksum_algorithm_crc64nvme(self): full_path = self.files.create_file('foo.txt', 'contents') cmdline = f'{self.prefix} {full_path} s3://bucket/key.txt --checksum-algorithm CRC64NVME' diff --git a/tests/functional/s3/test_mv_command.py b/tests/functional/s3/test_mv_command.py index dcddbad7ca5b..b7e6ca71ed63 100644 --- a/tests/functional/s3/test_mv_command.py +++ b/tests/functional/s3/test_mv_command.py @@ -370,7 +370,7 @@ def test_mv_works_if_outpost_access_point_arn_resolves_to_different_bucket(self) self.assertEqual(self.operations_called[2][0].name, 'CopyObject') self.assertEqual(self.operations_called[3][0].name, 'DeleteObject') - @requires_crt + @requires_crt() def test_mv_works_if_mrap_arn_resolves_to_different_bucket(self): cmdline = (f"{self.prefix} s3://bucket/key " "s3://arn:aws:s3::123456789012:accesspoint/foobar.mrap/key " @@ -429,7 +429,7 @@ def test_skips_validation_if_keys_are_different_outpost_alias(self): "--validate-same-s3-paths") self.assert_runs_mv_without_validation(cmdline) - @requires_crt + @requires_crt() def test_skips_validation_if_keys_are_different_mrap_arn(self): cmdline = (f"{self.prefix} s3://bucket/key " "s3://arn:aws:s3::123456789012:accesspoint/foobar.mrap/key2 " diff --git a/tests/unit/test_decorators.py b/tests/unit/test_decorators.py new file mode 100644 index 000000000000..563a64de75b3 --- /dev/null +++ b/tests/unit/test_decorators.py @@ -0,0 +1,45 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from unittest import mock + +import pytest + +from tests import requires_crt + + +class TestRequiresCrt: + def test_bare_requires_crt_fails_immediately(self): + with pytest.raises(TypeError): + + @requires_crt + def my_test(): + pass + + def test_requires_crt_skips_when_no_crt(self): + with mock.patch('tests.HAS_CRT', False): + + @requires_crt() + def my_test(): + assert False + + assert getattr(my_test, '__unittest_skip__', False) is True + + def test_requires_crt_runs_when_crt_available(self): + with mock.patch('tests.HAS_CRT', True): + + @requires_crt() + def my_test(): + pass + + assert getattr(my_test, '__unittest_skip__', False) is False