From 8cbfe3d5c177338c397e73fb9e2087b2ca12a246 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 12 Jan 2018 15:08:44 -0800 Subject: [PATCH 1/5] adding allowed pytest marks --- setup.cfg | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup.cfg b/setup.cfg index f3b5e0b36..2771afc9c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,6 +10,15 @@ branch = True [coverage:report] show_missing = True +[tool:pytest] +markers = + local: superset of unit and functional (does not require network access) + unit: mark test as a unit test (does not require network access) + functional: mark test as a functional test (does not require network access) + integ: mark a test as an integration test (requires network access) + accept: mark a test as an acceptance test (requires network access) + examples: mark a test as an examples test (requires network access) + # Flake8 Configuration [flake8] max_complexity = 10 From 09f120ce90715970e94cd378eb3bd528a98b65b9 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 12 Jan 2018 15:09:35 -0800 Subject: [PATCH 2/5] converting tests from skipping based on environment variables to using pytest marks to select tests https://github.com/awslabs/aws-encryption-sdk-python/issues/23 --- examples/test/test_i_basic_encryption.py | 5 ++-- ...file_encryption_with_multiple_providers.py | 5 ++-- ...c_file_encryption_with_raw_key_provider.py | 4 +-- .../test/test_i_data_key_caching_basic.py | 5 ++-- .../test_f_aws_encryption_sdk_client.py | 7 ++++- test/functional/test_f_crypto.py | 2 ++ test/functional/test_f_crypto_iv.py | 2 ++ test/functional/test_f_xcompat.py | 2 ++ test/integration/README.rst | 1 - test/integration/integration_test_utils.py | 26 ++++++++----------- .../test_i_aws_encrytion_sdk_client.py | 8 +++--- test/integration/test_i_thread_safety.py | 6 ++--- test/integration/test_i_xcompat_kms.py | 8 +++--- test/unit/test_aws_encryption_sdk.py | 3 +++ test/unit/test_caches.py | 2 ++ test/unit/test_caches_base.py | 2 ++ test/unit/test_caches_crypto_cache_entry.py | 2 ++ test/unit/test_caches_local.py | 2 ++ test/unit/test_caches_null.py | 2 ++ .../unit/test_crypto_authentication_signer.py | 2 ++ .../test_crypto_authentication_verifier.py | 2 ++ test/unit/test_crypto_data_keys.py | 2 ++ test/unit/test_crypto_elliptic_curve.py | 2 ++ test/unit/test_crypto_encryption_decryptor.py | 2 ++ test/unit/test_crypto_encryption_encryptor.py | 2 ++ .../test_crypto_prehashing_authenticator.py | 2 ++ test/unit/test_crypto_wrapping_keys.py | 2 ++ test/unit/test_defaults.py | 4 +++ test/unit/test_deserialize.py | 3 +++ test/unit/test_encryption_context.py | 3 +++ test/unit/test_identifiers.py | 2 ++ test/unit/test_internal_structures.py | 2 ++ test/unit/test_material_managers.py | 2 ++ test/unit/test_material_managers_base.py | 2 ++ test/unit/test_material_managers_caching.py | 2 ++ test/unit/test_material_managers_default.py | 2 ++ test/unit/test_providers_base_master_key.py | 2 ++ .../test_providers_base_master_key_config.py | 2 ++ ...test_providers_base_master_key_provider.py | 3 +++ test/unit/test_providers_kms_master_key.py | 3 +++ .../test_providers_kms_master_key_config.py | 2 ++ .../test_providers_kms_master_key_provider.py | 3 +++ ...roviders_kms_master_key_provider_config.py | 2 ++ test/unit/test_providers_raw_master_key.py | 3 +++ .../test_providers_raw_master_key_config.py | 2 ++ .../test_providers_raw_master_key_provider.py | 3 +++ test/unit/test_serialize.py | 2 ++ test/unit/test_streaming_client_configs.py | 2 ++ ...test_streaming_client_encryption_stream.py | 3 +++ .../test_streaming_client_stream_decryptor.py | 3 +++ .../test_streaming_client_stream_encryptor.py | 3 +++ test/unit/test_structures.py | 2 ++ test/unit/test_util_str_ops.py | 4 +++ test/unit/test_util_streams.py | 2 ++ test/unit/test_utils.py | 2 ++ 55 files changed, 144 insertions(+), 36 deletions(-) diff --git a/examples/test/test_i_basic_encryption.py b/examples/test/test_i_basic_encryption.py index 3feda0c59..87698ca60 100644 --- a/examples/test/test_i_basic_encryption.py +++ b/examples/test/test_i_basic_encryption.py @@ -22,10 +22,11 @@ import pytest from basic_encryption import cycle_string -from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests +from integration_test_utils import get_cmk_arn + +pytestmark = [pytest.mark.examples] -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) def test_cycle_string(): plaintext = os.urandom(1024) cmk_arn = get_cmk_arn() diff --git a/examples/test/test_i_basic_file_encryption_with_multiple_providers.py b/examples/test/test_i_basic_file_encryption_with_multiple_providers.py index b8c304f45..e5de4d2a2 100644 --- a/examples/test/test_i_basic_file_encryption_with_multiple_providers.py +++ b/examples/test/test_i_basic_file_encryption_with_multiple_providers.py @@ -23,10 +23,11 @@ import pytest from basic_file_encryption_with_multiple_providers import cycle_file -from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests +from integration_test_utils import get_cmk_arn + +pytestmark = [pytest.mark.examples] -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) def test_cycle_file(): cmk_arn = get_cmk_arn() _handle, filename = tempfile.mkstemp() diff --git a/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py b/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py index adb35ac27..cb0d3f5fa 100644 --- a/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py +++ b/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py @@ -22,10 +22,10 @@ import pytest from basic_file_encryption_with_raw_key_provider import cycle_file -from integration_test_utils import SKIP_MESSAGE, skip_tests + +pytestmark = [pytest.mark.examples] -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) def test_cycle_file(): _handle, filename = tempfile.mkstemp() with open(filename, 'wb') as f: diff --git a/examples/test/test_i_data_key_caching_basic.py b/examples/test/test_i_data_key_caching_basic.py index 338c66d22..7a02b14c3 100644 --- a/examples/test/test_i_data_key_caching_basic.py +++ b/examples/test/test_i_data_key_caching_basic.py @@ -21,10 +21,11 @@ import pytest from data_key_caching_basic import encrypt_with_caching -from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests +from integration_test_utils import get_cmk_arn + +pytestmark = [pytest.mark.examples] -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) def test_encrypt_with_caching(): cmk_arn = get_cmk_arn() encrypt_with_caching( diff --git a/test/functional/test_f_aws_encryption_sdk_client.py b/test/functional/test_f_aws_encryption_sdk_client.py index 03099cfc8..3876c265d 100644 --- a/test/functional/test_f_aws_encryption_sdk_client.py +++ b/test/functional/test_f_aws_encryption_sdk_client.py @@ -34,6 +34,8 @@ from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider from aws_encryption_sdk.materials_managers import DecryptionMaterialsRequest, EncryptionMaterialsRequest +pytestmark = [pytest.mark.functional, pytest.mark.local] + VALUES = { 'frame_lengths': ( # Assuming 1280 byte plaintext: 0, # Non-framed @@ -347,7 +349,10 @@ def test_encryption_cycle_raw_mkp(wrapping_algorithm, encryption_key_type, decry assert plaintext == VALUES['plaintext_128'] -@pytest.mark.skipif(not _mgf1_sha256_supported(), reason='MGF1-SHA256 not supported by this backend') +@pytest.mark.skipif( + not _mgf1_sha256_supported(), + reason='MGF1-SHA256 not supported by this backend: OpenSSL required v1.0.2+' +) @pytest.mark.parametrize('wrapping_algorithm, encryption_key_type, decryption_key_type', ( (WrappingAlgorithm.RSA_OAEP_SHA256_MGF1, EncryptionKeyType.PRIVATE, EncryptionKeyType.PRIVATE), (WrappingAlgorithm.RSA_OAEP_SHA256_MGF1, EncryptionKeyType.PUBLIC, EncryptionKeyType.PRIVATE) diff --git a/test/functional/test_f_crypto.py b/test/functional/test_f_crypto.py index 095257d30..cc9a19d5d 100644 --- a/test/functional/test_f_crypto.py +++ b/test/functional/test_f_crypto.py @@ -20,6 +20,8 @@ from aws_encryption_sdk.internal.crypto.authentication import Signer from aws_encryption_sdk.internal.crypto.elliptic_curve import _ecc_static_length_signature +pytestmark = [pytest.mark.functional, pytest.mark.local] + # Run several of each type to make get a high probability of forcing signature length correction @pytest.mark.parametrize('algorithm', [ diff --git a/test/functional/test_f_crypto_iv.py b/test/functional/test_f_crypto_iv.py index 63eefdeff..66428fdd5 100644 --- a/test/functional/test_f_crypto_iv.py +++ b/test/functional/test_f_crypto_iv.py @@ -17,6 +17,8 @@ from aws_encryption_sdk.internal.crypto.iv import frame_iv, header_auth_iv, non_framed_body_iv from aws_encryption_sdk.internal.defaults import ALGORITHM, MAX_FRAME_COUNT +pytestmark = [pytest.mark.functional, pytest.mark.local] + VALUES = { 'ivs': { 'header_auth': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', diff --git a/test/functional/test_f_xcompat.py b/test/functional/test_f_xcompat.py index 619b968fe..1d533b28d 100644 --- a/test/functional/test_f_xcompat.py +++ b/test/functional/test_f_xcompat.py @@ -29,6 +29,8 @@ from aws_encryption_sdk.internal.str_ops import to_bytes from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider +pytestmark = [pytest.mark.accept] + # Environment-specific test file locator. May not always exist. def _file_root(): diff --git a/test/integration/README.rst b/test/integration/README.rst index 84d64a888..33ecbbedd 100644 --- a/test/integration/README.rst +++ b/test/integration/README.rst @@ -7,7 +7,6 @@ In order to run these integration tests successfully, these things must be confi #. Ensure that AWS credentials are available in one of the `automatically discoverable credential locations`_. #. Set environment variable ``AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID`` to valid `AWS KMS key id`_ to use for integration tests. -#. Set environment variable ``AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL`` to ``RUN``. .. _automatically discoverable credential locations: http://boto3.readthedocs.io/en/latest/guide/configuration.html .. _AWS KMS key id: http://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html diff --git a/test/integration/integration_test_utils.py b/test/integration/integration_test_utils.py index e3f51de8a..60ac9de8b 100644 --- a/test/integration/integration_test_utils.py +++ b/test/integration/integration_test_utils.py @@ -10,30 +10,26 @@ # 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. -"""Utility functions to handle configuration, credentials setup, and test skip -decision making for integration tests.""" +"""Utility functions to handle configuration and credentials setup for integration tests.""" import os from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider -SKIP_MESSAGE = ( - 'Required environment variables not found. Skipping integration tests.' - ' See integration tests README.rst for more information.' -) -TEST_CONTROL = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL' AWS_KMS_KEY_ID = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID' -def skip_tests(): - """Only run tests if both required environment variables are found.""" - test_control = os.environ.get(TEST_CONTROL, None) - key_id = os.environ.get(AWS_KMS_KEY_ID, None) - return not (test_control == 'RUN' and key_id is not None) - - def get_cmk_arn(): """Retrieves the target CMK ARN from environment variable.""" - return os.environ.get(AWS_KMS_KEY_ID) + arn = os.environ.get(AWS_KMS_KEY_ID, None) + if arn is None: + raise ValueError( + 'Environment variable "{}" must be set to a valid KMS CMK ARN for integration tests to run'.format( + AWS_KMS_KEY_ID + ) + ) + if arn.startswith('arn:') and ':alias/' not in arn: + return arn + raise ValueError('KMS CMK ARN provided for integration tests much be a key not an alias') def setup_kms_master_key_provider(): diff --git a/test/integration/test_i_aws_encrytion_sdk_client.py b/test/integration/test_i_aws_encrytion_sdk_client.py index eadb73263..454ac1f89 100644 --- a/test/integration/test_i_aws_encrytion_sdk_client.py +++ b/test/integration/test_i_aws_encrytion_sdk_client.py @@ -14,9 +14,13 @@ import io import unittest +import pytest + import aws_encryption_sdk from aws_encryption_sdk.identifiers import Algorithm -from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests +from .integration_test_utils import setup_kms_master_key_provider + +pytestmark = [pytest.mark.integ] VALUES = { @@ -39,8 +43,6 @@ class TestKMSThickClientIntegration(unittest.TestCase): def setUp(self): - if skip_tests(): - self.skipTest(SKIP_MESSAGE) self.kms_master_key_provider = setup_kms_master_key_provider() def test_encryption_cycle_default_algorithm_framed_stream(self): diff --git a/test/integration/test_i_thread_safety.py b/test/integration/test_i_thread_safety.py index 1a3aed960..0c68d9d63 100644 --- a/test/integration/test_i_thread_safety.py +++ b/test/integration/test_i_thread_safety.py @@ -22,7 +22,9 @@ from six.moves import queue # six.moves confuses pylint: disable=import-error import aws_encryption_sdk -from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests +from .integration_test_utils import setup_kms_master_key_provider + +pytestmark = [pytest.mark.integ] PLAINTEXT = ( @@ -101,7 +103,6 @@ def random_pause_time(max_seconds=3): return SystemRandom().random() * 10 % max_seconds -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) def test_threading_loop(): """Test thread safety of client.""" rounds = 20 @@ -127,7 +128,6 @@ def test_threading_loop(): assert all(value == PLAINTEXT for value in decrypted_values) -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) def test_threading_loop_with_common_cache(): """Test thread safety of client while using common cryptographic materials cache across all threads.""" rounds = 20 diff --git a/test/integration/test_i_xcompat_kms.py b/test/integration/test_i_xcompat_kms.py index fb9908de6..c906bbdd0 100644 --- a/test/integration/test_i_xcompat_kms.py +++ b/test/integration/test_i_xcompat_kms.py @@ -17,7 +17,9 @@ import pytest import aws_encryption_sdk -from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests +from .integration_test_utils import setup_kms_master_key_provider + +pytestmark = [pytest.mark.accept] # Environment-specific test file locator. May not always exist. @@ -32,9 +34,6 @@ def _file_root(): def _generate_test_cases(): - if skip_tests(): - return [] - kms_key_provider = setup_kms_master_key_provider() try: root_dir = os.path.abspath(file_root()) @@ -73,7 +72,6 @@ def _generate_test_cases(): return _test_cases -@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE) @pytest.mark.parametrize('plaintext_filename,ciphertext_filename,key_provider', _generate_test_cases()) def test_decrypt_from_file(plaintext_filename, ciphertext_filename, key_provider): """Tests decrypt from known good files.""" diff --git a/test/unit/test_aws_encryption_sdk.py b/test/unit/test_aws_encryption_sdk.py index c5b1695c3..912ec0a37 100644 --- a/test/unit/test_aws_encryption_sdk.py +++ b/test/unit/test_aws_encryption_sdk.py @@ -14,11 +14,14 @@ import unittest from mock import MagicMock, patch, sentinel +import pytest import six import aws_encryption_sdk import aws_encryption_sdk.internal.defaults +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestAwsEncryptionSdk(unittest.TestCase): diff --git a/test/unit/test_caches.py b/test/unit/test_caches.py index 20ae3b950..40e7b4e0b 100644 --- a/test/unit/test_caches.py +++ b/test/unit/test_caches.py @@ -26,6 +26,8 @@ from aws_encryption_sdk.materials_managers import DecryptionMaterialsRequest, EncryptionMaterialsRequest from aws_encryption_sdk.structures import DataKey, MasterKeyInfo +pytestmark = [pytest.mark.unit, pytest.mark.local] + VALUES = { 'basic': { diff --git a/test/unit/test_caches_base.py b/test/unit/test_caches_base.py index a8c98cce4..6fc385693 100644 --- a/test/unit/test_caches_base.py +++ b/test/unit/test_caches_base.py @@ -15,6 +15,8 @@ from aws_encryption_sdk.caches.base import CryptoMaterialsCache +pytestmark = [pytest.mark.unit, pytest.mark.local] + def test_abstracts(): with pytest.raises(TypeError) as excinfo: diff --git a/test/unit/test_caches_crypto_cache_entry.py b/test/unit/test_caches_crypto_cache_entry.py index 9c038a269..0dbc736a9 100644 --- a/test/unit/test_caches_crypto_cache_entry.py +++ b/test/unit/test_caches_crypto_cache_entry.py @@ -22,6 +22,8 @@ from aws_encryption_sdk.exceptions import NotSupportedError from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials +pytestmark = [pytest.mark.unit, pytest.mark.local] + _VALID_KWARGS = { 'CryptoMaterialsCacheEntryHints': dict(lifetime=5.0), 'CryptoMaterialsCacheEntry': dict( diff --git a/test/unit/test_caches_local.py b/test/unit/test_caches_local.py index b6e6229f1..25baedd88 100644 --- a/test/unit/test_caches_local.py +++ b/test/unit/test_caches_local.py @@ -22,6 +22,8 @@ from aws_encryption_sdk.caches.local import _OPPORTUNISTIC_EVICTION_ROUNDS, LocalCryptoMaterialsCache from aws_encryption_sdk.exceptions import CacheKeyError, NotSupportedError +pytestmark = [pytest.mark.unit, pytest.mark.local] + def build_lcmc(**custom_kwargs): kwargs = dict(capacity=10) diff --git a/test/unit/test_caches_null.py b/test/unit/test_caches_null.py index c2f960615..4e7179452 100644 --- a/test/unit/test_caches_null.py +++ b/test/unit/test_caches_null.py @@ -19,6 +19,8 @@ from aws_encryption_sdk.exceptions import CacheKeyError from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials +pytestmark = [pytest.mark.unit, pytest.mark.local] + def test_put_encryption_materials(): cache_key = b'ex_cache_key' diff --git a/test/unit/test_crypto_authentication_signer.py b/test/unit/test_crypto_authentication_signer.py index 6c8cf7d5a..ee8a0f788 100644 --- a/test/unit/test_crypto_authentication_signer.py +++ b/test/unit/test_crypto_authentication_signer.py @@ -20,6 +20,8 @@ from aws_encryption_sdk.internal.defaults import ALGORITHM from .test_crypto import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_crypto_authentication_verifier.py b/test/unit/test_crypto_authentication_verifier.py index a3a0e3037..725fb9900 100644 --- a/test/unit/test_crypto_authentication_verifier.py +++ b/test/unit/test_crypto_authentication_verifier.py @@ -20,6 +20,8 @@ from aws_encryption_sdk.internal.defaults import ALGORITHM from .test_crypto import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_crypto_data_keys.py b/test/unit/test_crypto_data_keys.py index f9701be2b..32197001e 100644 --- a/test/unit/test_crypto_data_keys.py +++ b/test/unit/test_crypto_data_keys.py @@ -18,6 +18,8 @@ import aws_encryption_sdk.internal.crypto.data_keys from aws_encryption_sdk.internal.crypto.data_keys import derive_data_encryption_key +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_crypto_elliptic_curve.py b/test/unit/test_crypto_elliptic_curve.py index 0c47cbe82..c4a920b3b 100644 --- a/test/unit/test_crypto_elliptic_curve.py +++ b/test/unit/test_crypto_elliptic_curve.py @@ -28,6 +28,8 @@ ) from .test_crypto import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_crypto_encryption_decryptor.py b/test/unit/test_crypto_encryption_decryptor.py index 811b7836f..093d8bd61 100644 --- a/test/unit/test_crypto_encryption_decryptor.py +++ b/test/unit/test_crypto_encryption_decryptor.py @@ -18,6 +18,8 @@ import aws_encryption_sdk.internal.crypto.encryption from aws_encryption_sdk.internal.crypto.encryption import decrypt, Decryptor +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_crypto_encryption_encryptor.py b/test/unit/test_crypto_encryption_encryptor.py index 414055a30..1a943b516 100644 --- a/test/unit/test_crypto_encryption_encryptor.py +++ b/test/unit/test_crypto_encryption_encryptor.py @@ -19,6 +19,8 @@ from aws_encryption_sdk.internal.crypto.encryption import encrypt, Encryptor from aws_encryption_sdk.internal.structures import EncryptedData +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_crypto_prehashing_authenticator.py b/test/unit/test_crypto_prehashing_authenticator.py index 6dc99aa45..956d48f56 100644 --- a/test/unit/test_crypto_prehashing_authenticator.py +++ b/test/unit/test_crypto_prehashing_authenticator.py @@ -20,6 +20,8 @@ import aws_encryption_sdk.internal.crypto.authentication from aws_encryption_sdk.internal.crypto.authentication import _PrehashingAuthenticator +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_set_signature_type(mocker): diff --git a/test/unit/test_crypto_wrapping_keys.py b/test/unit/test_crypto_wrapping_keys.py index eada1b78b..c257e55c4 100644 --- a/test/unit/test_crypto_wrapping_keys.py +++ b/test/unit/test_crypto_wrapping_keys.py @@ -22,6 +22,8 @@ from aws_encryption_sdk.internal.structures import EncryptedData from .test_crypto import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.yield_fixture def patch_default_backend(mocker): diff --git a/test/unit/test_defaults.py b/test/unit/test_defaults.py index 9f734213b..54d512f91 100644 --- a/test/unit/test_defaults.py +++ b/test/unit/test_defaults.py @@ -13,8 +13,12 @@ """Test suite to verify calculated values in aws_encryption_sdk.internal.defaults""" import unittest +import pytest + import aws_encryption_sdk.internal.defaults +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestDefaults(unittest.TestCase): diff --git a/test/unit/test_deserialize.py b/test/unit/test_deserialize.py index 8a963482d..2b848859a 100644 --- a/test/unit/test_deserialize.py +++ b/test/unit/test_deserialize.py @@ -16,6 +16,7 @@ from cryptography.exceptions import InvalidTag from mock import MagicMock, patch, sentinel +import pytest import six from aws_encryption_sdk.exceptions import NotSupportedError, SerializationError, UnknownIdentityError @@ -24,6 +25,8 @@ from aws_encryption_sdk.internal.structures import EncryptedData from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestDeserialize(unittest.TestCase): diff --git a/test/unit/test_encryption_context.py b/test/unit/test_encryption_context.py index c1b2b1892..991b18a48 100644 --- a/test/unit/test_encryption_context.py +++ b/test/unit/test_encryption_context.py @@ -13,6 +13,7 @@ """Unit test suite for aws_encryption_sdk.internal.formatting.encryption_context""" import unittest +import pytest import six from aws_encryption_sdk.exceptions import SerializationError @@ -21,6 +22,8 @@ import aws_encryption_sdk.internal.formatting.encryption_context from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestEncryptionContext(unittest.TestCase): diff --git a/test/unit/test_identifiers.py b/test/unit/test_identifiers.py index 300728e83..a1db95b82 100644 --- a/test/unit/test_identifiers.py +++ b/test/unit/test_identifiers.py @@ -17,6 +17,8 @@ from aws_encryption_sdk.exceptions import InvalidAlgorithmError from aws_encryption_sdk.identifiers import Algorithm, EncryptionSuite, KDFSuite +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.mark.parametrize('check_algorithm, safe_to_cache', ( (Algorithm.AES_128_GCM_IV12_TAG16, False), diff --git a/test/unit/test_internal_structures.py b/test/unit/test_internal_structures.py index 0fe16b50f..c61cf0161 100644 --- a/test/unit/test_internal_structures.py +++ b/test/unit/test_internal_structures.py @@ -18,6 +18,8 @@ ) from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs +pytestmark = [pytest.mark.unit, pytest.mark.local] + VALID_KWARGS = { EncryptedData: [ diff --git a/test/unit/test_material_managers.py b/test/unit/test_material_managers.py index 5064c7fd7..649253e08 100644 --- a/test/unit/test_material_managers.py +++ b/test/unit/test_material_managers.py @@ -23,6 +23,8 @@ ) from aws_encryption_sdk.structures import DataKey +pytestmark = [pytest.mark.unit, pytest.mark.local] + _VALID_KWARGS = { 'EncryptionMaterialsRequest': dict( diff --git a/test/unit/test_material_managers_base.py b/test/unit/test_material_managers_base.py index bd964b774..75f4d0265 100644 --- a/test/unit/test_material_managers_base.py +++ b/test/unit/test_material_managers_base.py @@ -15,6 +15,8 @@ from aws_encryption_sdk.materials_managers.base import CryptoMaterialsManager +pytestmark = [pytest.mark.unit, pytest.mark.local] + def test_abstracts(): with pytest.raises(TypeError) as excinfo: diff --git a/test/unit/test_material_managers_caching.py b/test/unit/test_material_managers_caching.py index 29a0c1a55..ac115b59a 100644 --- a/test/unit/test_material_managers_caching.py +++ b/test/unit/test_material_managers_caching.py @@ -24,6 +24,8 @@ import aws_encryption_sdk.materials_managers.caching from aws_encryption_sdk.materials_managers.caching import CachingCryptoMaterialsManager +pytestmark = [pytest.mark.unit, pytest.mark.local] + def build_ccmm(**custom_kwargs): kwargs = dict( diff --git a/test/unit/test_material_managers_default.py b/test/unit/test_material_managers_default.py index d0da70584..cfdbd8386 100644 --- a/test/unit/test_material_managers_default.py +++ b/test/unit/test_material_managers_default.py @@ -25,6 +25,8 @@ from aws_encryption_sdk.materials_managers.default import DefaultCryptoMaterialsManager from aws_encryption_sdk.structures import DataKey +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.fixture def patch_for_dcmm_encrypt(mocker): diff --git a/test/unit/test_providers_base_master_key.py b/test/unit/test_providers_base_master_key.py index cb7e484f6..7107c7f1f 100644 --- a/test/unit/test_providers_base_master_key.py +++ b/test/unit/test_providers_base_master_key.py @@ -24,6 +24,8 @@ from aws_encryption_sdk.structures import MasterKeyInfo from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @attr.s(hash=True) class MockMasterKeyConfig(MasterKeyConfig): diff --git a/test/unit/test_providers_base_master_key_config.py b/test/unit/test_providers_base_master_key_config.py index 57f16c046..e9c399929 100644 --- a/test/unit/test_providers_base_master_key_config.py +++ b/test/unit/test_providers_base_master_key_config.py @@ -16,6 +16,8 @@ from aws_encryption_sdk.key_providers.base import MasterKeyConfig from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs +pytestmark = [pytest.mark.unit, pytest.mark.local] + class FakeMasterKeyConfig(MasterKeyConfig): provider_id = None diff --git a/test/unit/test_providers_base_master_key_provider.py b/test/unit/test_providers_base_master_key_provider.py index 3506d6a6c..f47b6e4ef 100644 --- a/test/unit/test_providers_base_master_key_provider.py +++ b/test/unit/test_providers_base_master_key_provider.py @@ -15,6 +15,7 @@ import attr from mock import call, MagicMock, patch, PropertyMock, sentinel +import pytest import six from aws_encryption_sdk.exceptions import ( @@ -23,6 +24,8 @@ from aws_encryption_sdk.key_providers.base import MasterKeyProvider, MasterKeyProviderConfig from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @attr.s(hash=True) class MockMasterKeyProviderConfig(MasterKeyProviderConfig): diff --git a/test/unit/test_providers_kms_master_key.py b/test/unit/test_providers_kms_master_key.py index 118ea25da..3eaad7f4e 100644 --- a/test/unit/test_providers_kms_master_key.py +++ b/test/unit/test_providers_kms_master_key.py @@ -16,6 +16,7 @@ import botocore.client from botocore.exceptions import ClientError from mock import MagicMock, patch, sentinel +import pytest import six from aws_encryption_sdk.exceptions import DecryptKeyError, EncryptKeyError, GenerateKeyError @@ -25,6 +26,8 @@ from aws_encryption_sdk.structures import DataKey, EncryptedDataKey, MasterKeyInfo from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestKMSMasterKey(unittest.TestCase): diff --git a/test/unit/test_providers_kms_master_key_config.py b/test/unit/test_providers_kms_master_key_config.py index bcdd00d41..ab63deb5d 100644 --- a/test/unit/test_providers_kms_master_key_config.py +++ b/test/unit/test_providers_kms_master_key_config.py @@ -18,6 +18,8 @@ from aws_encryption_sdk.key_providers.kms import _PROVIDER_ID, KMSMasterKeyConfig from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs +pytestmark = [pytest.mark.unit, pytest.mark.local] + VALID_KWARGS = { KMSMasterKeyConfig: [ diff --git a/test/unit/test_providers_kms_master_key_provider.py b/test/unit/test_providers_kms_master_key_provider.py index c234e6669..f68a10041 100644 --- a/test/unit/test_providers_kms_master_key_provider.py +++ b/test/unit/test_providers_kms_master_key_provider.py @@ -15,12 +15,15 @@ import botocore.client from mock import ANY, call, MagicMock, patch, sentinel +import pytest import six from aws_encryption_sdk.exceptions import UnknownRegionError from aws_encryption_sdk.key_providers.base import MasterKeyProvider from aws_encryption_sdk.key_providers.kms import KMSMasterKey, KMSMasterKeyProvider +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestKMSMasterKeyProvider(unittest.TestCase): diff --git a/test/unit/test_providers_kms_master_key_provider_config.py b/test/unit/test_providers_kms_master_key_provider_config.py index 62e24cb67..10eb8d02a 100644 --- a/test/unit/test_providers_kms_master_key_provider_config.py +++ b/test/unit/test_providers_kms_master_key_provider_config.py @@ -18,6 +18,8 @@ from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProviderConfig from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs +pytestmark = [pytest.mark.unit, pytest.mark.local] + VALID_KWARGS = { KMSMasterKeyProviderConfig: [ diff --git a/test/unit/test_providers_raw_master_key.py b/test/unit/test_providers_raw_master_key.py index a695c412d..7615d9f9a 100644 --- a/test/unit/test_providers_raw_master_key.py +++ b/test/unit/test_providers_raw_master_key.py @@ -14,6 +14,7 @@ import unittest from mock import MagicMock, patch, sentinel +import pytest from aws_encryption_sdk.identifiers import Algorithm, WrappingAlgorithm from aws_encryption_sdk.internal.crypto.wrapping_keys import WrappingKey @@ -22,6 +23,8 @@ from aws_encryption_sdk.structures import DataKey, EncryptedDataKey, MasterKeyInfo, RawDataKey from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestRawMasterKey(unittest.TestCase): diff --git a/test/unit/test_providers_raw_master_key_config.py b/test/unit/test_providers_raw_master_key_config.py index 1e68cfa57..4781a11ac 100644 --- a/test/unit/test_providers_raw_master_key_config.py +++ b/test/unit/test_providers_raw_master_key_config.py @@ -20,6 +20,8 @@ from aws_encryption_sdk.key_providers.raw import RawMasterKeyConfig from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs +pytestmark = [pytest.mark.unit, pytest.mark.local] + STATIC_WRAPPING_KEY = WrappingKey( wrapping_algorithm=WrappingAlgorithm.AES_256_GCM_IV12_TAG16_NO_PADDING, wrapping_key=b'_________a symmetric key________', diff --git a/test/unit/test_providers_raw_master_key_provider.py b/test/unit/test_providers_raw_master_key_provider.py index efe972ef7..79929fc52 100644 --- a/test/unit/test_providers_raw_master_key_provider.py +++ b/test/unit/test_providers_raw_master_key_provider.py @@ -15,12 +15,15 @@ import attr from mock import MagicMock, patch, sentinel +import pytest import six from aws_encryption_sdk.key_providers.base import MasterKeyProvider, MasterKeyProviderConfig from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + _MOCK_RAW_MASTER_KEY = MagicMock() diff --git a/test/unit/test_serialize.py b/test/unit/test_serialize.py index 9e0254a9c..07c340576 100644 --- a/test/unit/test_serialize.py +++ b/test/unit/test_serialize.py @@ -24,6 +24,8 @@ from aws_encryption_sdk.structures import EncryptedDataKey, MasterKeyInfo from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.mark.parametrize('sequence_number, error_message', ( (-1, r'Frame sequence number must be greater than 0'), diff --git a/test/unit/test_streaming_client_configs.py b/test/unit/test_streaming_client_configs.py index 674ef0d7e..9fe51b918 100644 --- a/test/unit/test_streaming_client_configs.py +++ b/test/unit/test_streaming_client_configs.py @@ -23,6 +23,8 @@ from aws_encryption_sdk.streaming_client import _ClientConfig, DecryptorConfig, EncryptorConfig from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs, build_valid_kwargs_list +pytestmark = [pytest.mark.unit, pytest.mark.local] + class FakeCryptoMaterialsManager(CryptoMaterialsManager): diff --git a/test/unit/test_streaming_client_encryption_stream.py b/test/unit/test_streaming_client_encryption_stream.py index f5dbe9efd..1f5a13660 100644 --- a/test/unit/test_streaming_client_encryption_stream.py +++ b/test/unit/test_streaming_client_encryption_stream.py @@ -16,6 +16,7 @@ import attr from mock import call, MagicMock, patch, PropertyMock, sentinel +import pytest import six import aws_encryption_sdk.exceptions @@ -24,6 +25,8 @@ from aws_encryption_sdk.streaming_client import _ClientConfig, _EncryptionStream from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @attr.s class MockClientConfig(_ClientConfig): diff --git a/test/unit/test_streaming_client_stream_decryptor.py b/test/unit/test_streaming_client_stream_decryptor.py index 690660f9e..d6096976f 100644 --- a/test/unit/test_streaming_client_stream_decryptor.py +++ b/test/unit/test_streaming_client_stream_decryptor.py @@ -15,6 +15,7 @@ import unittest from mock import call, MagicMock, patch, sentinel +import pytest import six from aws_encryption_sdk.exceptions import CustomMaximumValueExceeded, NotSupportedError, SerializationError @@ -24,6 +25,8 @@ from aws_encryption_sdk.streaming_client import StreamDecryptor from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestStreamDecryptor(unittest.TestCase): diff --git a/test/unit/test_streaming_client_stream_encryptor.py b/test/unit/test_streaming_client_stream_encryptor.py index f3fbbdc28..352f062dc 100644 --- a/test/unit/test_streaming_client_stream_encryptor.py +++ b/test/unit/test_streaming_client_stream_encryptor.py @@ -15,6 +15,7 @@ import unittest from mock import call, MagicMock, patch, sentinel +import pytest import six from aws_encryption_sdk.exceptions import ( @@ -28,6 +29,8 @@ from aws_encryption_sdk.structures import MessageHeader from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestStreamEncryptor(unittest.TestCase): diff --git a/test/unit/test_structures.py b/test/unit/test_structures.py index 77fc85165..cd33a0597 100644 --- a/test/unit/test_structures.py +++ b/test/unit/test_structures.py @@ -21,6 +21,8 @@ ) from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs +pytestmark = [pytest.mark.unit, pytest.mark.local] + VALID_KWARGS = { MessageHeader: [dict( diff --git a/test/unit/test_util_str_ops.py b/test/unit/test_util_str_ops.py index 704ba5672..37a529194 100644 --- a/test/unit/test_util_str_ops.py +++ b/test/unit/test_util_str_ops.py @@ -15,8 +15,12 @@ import codecs import unittest +import pytest + import aws_encryption_sdk.internal.str_ops +pytestmark = [pytest.mark.unit, pytest.mark.local] + class TestStrOps(unittest.TestCase): diff --git a/test/unit/test_util_streams.py b/test/unit/test_util_streams.py index 55822c115..8905cf42e 100644 --- a/test/unit/test_util_streams.py +++ b/test/unit/test_util_streams.py @@ -18,6 +18,8 @@ from aws_encryption_sdk.exceptions import ActionNotAllowedError from aws_encryption_sdk.internal.utils.streams import ROStream, TeeStream +pytestmark = [pytest.mark.unit, pytest.mark.local] + def data(): return io.BytesIO(b'asdijfhoaisjdfoiasjdfoijawef') diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index 939a1c8df..1c55f7820 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -24,6 +24,8 @@ from aws_encryption_sdk.structures import DataKey, EncryptedDataKey, MasterKeyInfo, RawDataKey from .test_values import VALUES +pytestmark = [pytest.mark.unit, pytest.mark.local] + @pytest.mark.parametrize('user_agent, suffix, output', ( (None, 'test_suffix', 'test_suffix'), From f8fe81f0fad110fb5ea6d1e69e9d7666afd8b0bb Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 12 Jan 2018 15:10:03 -0800 Subject: [PATCH 3/5] updating test runners to use pytest marks --- .travis.yml | 34 ++++++++++++++++++++++++++++------ tox.ini | 16 ++++++---------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index b23b97e70..4f9efddeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,37 @@ language: python matrix: include: - python: 2.7 - env: TOXENV=py27 + env: TOXENV=py27-local + - python: 2.7 + env: TOXENV=py27-integ + - python: 2.7 + env: TOXENV=py27-accept + - python: 2.7 + env: TOXENV=py27-examples + - python: 3.4 + env: TOXENV=py34-local - python: 3.4 - env: TOXENV=py34 + env: TOXENV=py34-integ + - python: 3.4 + env: TOXENV=py34-accept + - python: 3.4 + env: TOXENV=py34-examples + - python: 3.5 + env: TOXENV=py35-local - python: 3.5 - env: TOXENV=py35 + env: TOXENV=py35-integ + - python: 3.5 + env: TOXENV=py35-accept + - python: 3.5 + env: TOXENV=py35-examples + - python: 3.6 + env: TOXENV=py36-local - python: 3.6 - env: TOXENV=py36 + env: TOXENV=py36-integ + - python: 3.6 + env: TOXENV=py36-accept + - python: 3.6 + env: TOXENV=py36-examples - python: 3.6 env: TOXENV=bandit - python: 3.6 @@ -27,8 +51,6 @@ matrix: env: TOXENV=flake8-tests - python: 3.6 env: TOXENV=pylint-tests - - python: 3.6 - env: TOXENV=examples - python: 3.6 env: TOXENV=flake8-examples - python: 3.6 diff --git a/tox.ini b/tox.ini index d5080473b..1ad373168 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,9 @@ [tox] envlist = - py{27,34,35,36}, + py{27,34,35,36}-{local,integ,accept,examples}, bandit, doc8, readme, docs, flake8, pylint, flake8-tests, pylint-tests, - examples, flake8-examples, pylint-examples # Additional test environments: @@ -21,12 +20,7 @@ envlist = # release :: Builds dist files and uploads to pypi pypirc profile. [testenv] -# _TEST_CONTROL : -# _AWS_KMS_KEY_ID : -# AWS_ACCESS/SECRET/TOKEN : passenv = - # Enables or disables integration tests ('RUN' enables) - AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL \ # Identifies AWS KMS key id to use in integration tests AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID \ # Pass through AWS credentials @@ -39,9 +33,11 @@ deps = pytest-mock coverage commands = - coverage run -m pytest \ - --cov aws_encryption_sdk \ - {posargs} + local: pytest --cov aws_encryption_sdk -m local -l {posargs} + integ: pytest --cov aws_encryption_sdk -m integ -l {posargs} + accept: pytest --cov aws_encryption_sdk -m accept -l {posargs} + all: pytest --cov aws_encryption_sdk -l {posargs} + examples: pytest --cov examples/test/ -m examples -l {posargs} # Examples [testenv:examples] From fc220fc4096d91eade3420c8c2d02af764dabe69 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 12 Jan 2018 15:41:36 -0800 Subject: [PATCH 4/5] condensing tox linting envlist listing --- tox.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 1ad373168..6bebf4f57 100644 --- a/tox.ini +++ b/tox.ini @@ -2,9 +2,7 @@ envlist = py{27,34,35,36}-{local,integ,accept,examples}, bandit, doc8, readme, docs, - flake8, pylint, - flake8-tests, pylint-tests, - flake8-examples, pylint-examples + {flake8,pylint}{,-tests,-examples} # Additional test environments: # vulture :: Runs vulture. Prone to false-positives. From a3d7a59fb46eec60b0bd2b58beadb90d442f1054 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 12 Jan 2018 15:43:15 -0800 Subject: [PATCH 5/5] removing deprecated "examples" tox testenv --- tox.ini | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tox.ini b/tox.ini index 6bebf4f57..143e68c1c 100644 --- a/tox.ini +++ b/tox.ini @@ -37,13 +37,6 @@ commands = all: pytest --cov aws_encryption_sdk -l {posargs} examples: pytest --cov examples/test/ -m examples -l {posargs} -# Examples -[testenv:examples] -basepython = python3 -commands = - coverage run -m pytest \ - examples/test/ - # Linters [testenv:flake8] basepython = python3