Skip to content

Commit 09f120c

Browse files
committed
converting tests from skipping based on environment variables to using pytest marks to select tests #23
1 parent 8cbfe3d commit 09f120c

File tree

55 files changed

+144
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+144
-36
lines changed

examples/test/test_i_basic_encryption.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import pytest
2323

2424
from basic_encryption import cycle_string
25-
from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests
25+
from integration_test_utils import get_cmk_arn
26+
27+
pytestmark = [pytest.mark.examples]
2628

2729

28-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
2930
def test_cycle_string():
3031
plaintext = os.urandom(1024)
3132
cmk_arn = get_cmk_arn()

examples/test/test_i_basic_file_encryption_with_multiple_providers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import pytest
2424

2525
from basic_file_encryption_with_multiple_providers import cycle_file
26-
from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests
26+
from integration_test_utils import get_cmk_arn
27+
28+
pytestmark = [pytest.mark.examples]
2729

2830

29-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
3031
def test_cycle_file():
3132
cmk_arn = get_cmk_arn()
3233
_handle, filename = tempfile.mkstemp()

examples/test/test_i_basic_file_encryption_with_raw_key_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import pytest
2323

2424
from basic_file_encryption_with_raw_key_provider import cycle_file
25-
from integration_test_utils import SKIP_MESSAGE, skip_tests
25+
26+
pytestmark = [pytest.mark.examples]
2627

2728

28-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
2929
def test_cycle_file():
3030
_handle, filename = tempfile.mkstemp()
3131
with open(filename, 'wb') as f:

examples/test/test_i_data_key_caching_basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
import pytest
2222

2323
from data_key_caching_basic import encrypt_with_caching
24-
from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests
24+
from integration_test_utils import get_cmk_arn
25+
26+
pytestmark = [pytest.mark.examples]
2527

2628

27-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
2829
def test_encrypt_with_caching():
2930
cmk_arn = get_cmk_arn()
3031
encrypt_with_caching(

test/functional/test_f_aws_encryption_sdk_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider
3535
from aws_encryption_sdk.materials_managers import DecryptionMaterialsRequest, EncryptionMaterialsRequest
3636

37+
pytestmark = [pytest.mark.functional, pytest.mark.local]
38+
3739
VALUES = {
3840
'frame_lengths': ( # Assuming 1280 byte plaintext:
3941
0, # Non-framed
@@ -347,7 +349,10 @@ def test_encryption_cycle_raw_mkp(wrapping_algorithm, encryption_key_type, decry
347349
assert plaintext == VALUES['plaintext_128']
348350

349351

350-
@pytest.mark.skipif(not _mgf1_sha256_supported(), reason='MGF1-SHA256 not supported by this backend')
352+
@pytest.mark.skipif(
353+
not _mgf1_sha256_supported(),
354+
reason='MGF1-SHA256 not supported by this backend: OpenSSL required v1.0.2+'
355+
)
351356
@pytest.mark.parametrize('wrapping_algorithm, encryption_key_type, decryption_key_type', (
352357
(WrappingAlgorithm.RSA_OAEP_SHA256_MGF1, EncryptionKeyType.PRIVATE, EncryptionKeyType.PRIVATE),
353358
(WrappingAlgorithm.RSA_OAEP_SHA256_MGF1, EncryptionKeyType.PUBLIC, EncryptionKeyType.PRIVATE)

test/functional/test_f_crypto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from aws_encryption_sdk.internal.crypto.authentication import Signer
2121
from aws_encryption_sdk.internal.crypto.elliptic_curve import _ecc_static_length_signature
2222

23+
pytestmark = [pytest.mark.functional, pytest.mark.local]
24+
2325

2426
# Run several of each type to make get a high probability of forcing signature length correction
2527
@pytest.mark.parametrize('algorithm', [

test/functional/test_f_crypto_iv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from aws_encryption_sdk.internal.crypto.iv import frame_iv, header_auth_iv, non_framed_body_iv
1818
from aws_encryption_sdk.internal.defaults import ALGORITHM, MAX_FRAME_COUNT
1919

20+
pytestmark = [pytest.mark.functional, pytest.mark.local]
21+
2022
VALUES = {
2123
'ivs': {
2224
'header_auth': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',

test/functional/test_f_xcompat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from aws_encryption_sdk.internal.str_ops import to_bytes
3030
from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider
3131

32+
pytestmark = [pytest.mark.accept]
33+
3234

3335
# Environment-specific test file locator. May not always exist.
3436
def _file_root():

test/integration/README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ In order to run these integration tests successfully, these things must be confi
77
#. Ensure that AWS credentials are available in one of the `automatically discoverable credential locations`_.
88
#. Set environment variable ``AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID`` to valid
99
`AWS KMS key id`_ to use for integration tests.
10-
#. Set environment variable ``AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL`` to ``RUN``.
1110

1211
.. _automatically discoverable credential locations: http://boto3.readthedocs.io/en/latest/guide/configuration.html
1312
.. _AWS KMS key id: http://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html

test/integration/integration_test_utils.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,26 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""Utility functions to handle configuration, credentials setup, and test skip
14-
decision making for integration tests."""
13+
"""Utility functions to handle configuration and credentials setup for integration tests."""
1514
import os
1615

1716
from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
1817

19-
SKIP_MESSAGE = (
20-
'Required environment variables not found. Skipping integration tests.'
21-
' See integration tests README.rst for more information.'
22-
)
23-
TEST_CONTROL = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL'
2418
AWS_KMS_KEY_ID = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID'
2519

2620

27-
def skip_tests():
28-
"""Only run tests if both required environment variables are found."""
29-
test_control = os.environ.get(TEST_CONTROL, None)
30-
key_id = os.environ.get(AWS_KMS_KEY_ID, None)
31-
return not (test_control == 'RUN' and key_id is not None)
32-
33-
3421
def get_cmk_arn():
3522
"""Retrieves the target CMK ARN from environment variable."""
36-
return os.environ.get(AWS_KMS_KEY_ID)
23+
arn = os.environ.get(AWS_KMS_KEY_ID, None)
24+
if arn is None:
25+
raise ValueError(
26+
'Environment variable "{}" must be set to a valid KMS CMK ARN for integration tests to run'.format(
27+
AWS_KMS_KEY_ID
28+
)
29+
)
30+
if arn.startswith('arn:') and ':alias/' not in arn:
31+
return arn
32+
raise ValueError('KMS CMK ARN provided for integration tests much be a key not an alias')
3733

3834

3935
def setup_kms_master_key_provider():

test/integration/test_i_aws_encrytion_sdk_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
import io
1515
import unittest
1616

17+
import pytest
18+
1719
import aws_encryption_sdk
1820
from aws_encryption_sdk.identifiers import Algorithm
19-
from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests
21+
from .integration_test_utils import setup_kms_master_key_provider
22+
23+
pytestmark = [pytest.mark.integ]
2024

2125

2226
VALUES = {
@@ -39,8 +43,6 @@
3943
class TestKMSThickClientIntegration(unittest.TestCase):
4044

4145
def setUp(self):
42-
if skip_tests():
43-
self.skipTest(SKIP_MESSAGE)
4446
self.kms_master_key_provider = setup_kms_master_key_provider()
4547

4648
def test_encryption_cycle_default_algorithm_framed_stream(self):

test/integration/test_i_thread_safety.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
from six.moves import queue # six.moves confuses pylint: disable=import-error
2323

2424
import aws_encryption_sdk
25-
from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests
25+
from .integration_test_utils import setup_kms_master_key_provider
26+
27+
pytestmark = [pytest.mark.integ]
2628

2729

2830
PLAINTEXT = (
@@ -101,7 +103,6 @@ def random_pause_time(max_seconds=3):
101103
return SystemRandom().random() * 10 % max_seconds
102104

103105

104-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
105106
def test_threading_loop():
106107
"""Test thread safety of client."""
107108
rounds = 20
@@ -127,7 +128,6 @@ def test_threading_loop():
127128
assert all(value == PLAINTEXT for value in decrypted_values)
128129

129130

130-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
131131
def test_threading_loop_with_common_cache():
132132
"""Test thread safety of client while using common cryptographic materials cache across all threads."""
133133
rounds = 20

test/integration/test_i_xcompat_kms.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import pytest
1818

1919
import aws_encryption_sdk
20-
from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests
20+
from .integration_test_utils import setup_kms_master_key_provider
21+
22+
pytestmark = [pytest.mark.accept]
2123

2224

2325
# Environment-specific test file locator. May not always exist.
@@ -32,9 +34,6 @@ def _file_root():
3234

3335

3436
def _generate_test_cases():
35-
if skip_tests():
36-
return []
37-
3837
kms_key_provider = setup_kms_master_key_provider()
3938
try:
4039
root_dir = os.path.abspath(file_root())
@@ -73,7 +72,6 @@ def _generate_test_cases():
7372
return _test_cases
7473

7574

76-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
7775
@pytest.mark.parametrize('plaintext_filename,ciphertext_filename,key_provider', _generate_test_cases())
7876
def test_decrypt_from_file(plaintext_filename, ciphertext_filename, key_provider):
7977
"""Tests decrypt from known good files."""

test/unit/test_aws_encryption_sdk.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
import unittest
1515

1616
from mock import MagicMock, patch, sentinel
17+
import pytest
1718
import six
1819

1920
import aws_encryption_sdk
2021
import aws_encryption_sdk.internal.defaults
2122

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2225

2326
class TestAwsEncryptionSdk(unittest.TestCase):
2427

test/unit/test_caches.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from aws_encryption_sdk.materials_managers import DecryptionMaterialsRequest, EncryptionMaterialsRequest
2727
from aws_encryption_sdk.structures import DataKey, MasterKeyInfo
2828

29+
pytestmark = [pytest.mark.unit, pytest.mark.local]
30+
2931

3032
VALUES = {
3133
'basic': {

test/unit/test_caches_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from aws_encryption_sdk.caches.base import CryptoMaterialsCache
1717

18+
pytestmark = [pytest.mark.unit, pytest.mark.local]
19+
1820

1921
def test_abstracts():
2022
with pytest.raises(TypeError) as excinfo:

test/unit/test_caches_crypto_cache_entry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from aws_encryption_sdk.exceptions import NotSupportedError
2323
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
2424

25+
pytestmark = [pytest.mark.unit, pytest.mark.local]
26+
2527
_VALID_KWARGS = {
2628
'CryptoMaterialsCacheEntryHints': dict(lifetime=5.0),
2729
'CryptoMaterialsCacheEntry': dict(

test/unit/test_caches_local.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from aws_encryption_sdk.caches.local import _OPPORTUNISTIC_EVICTION_ROUNDS, LocalCryptoMaterialsCache
2323
from aws_encryption_sdk.exceptions import CacheKeyError, NotSupportedError
2424

25+
pytestmark = [pytest.mark.unit, pytest.mark.local]
26+
2527

2628
def build_lcmc(**custom_kwargs):
2729
kwargs = dict(capacity=10)

test/unit/test_caches_null.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from aws_encryption_sdk.exceptions import CacheKeyError
2020
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
2121

22+
pytestmark = [pytest.mark.unit, pytest.mark.local]
23+
2224

2325
def test_put_encryption_materials():
2426
cache_key = b'ex_cache_key'

test/unit/test_crypto_authentication_signer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from aws_encryption_sdk.internal.defaults import ALGORITHM
2121
from .test_crypto import VALUES
2222

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2325

2426
@pytest.yield_fixture
2527
def patch_default_backend(mocker):

test/unit/test_crypto_authentication_verifier.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from aws_encryption_sdk.internal.defaults import ALGORITHM
2121
from .test_crypto import VALUES
2222

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2325

2426
@pytest.yield_fixture
2527
def patch_default_backend(mocker):

test/unit/test_crypto_data_keys.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import aws_encryption_sdk.internal.crypto.data_keys
1919
from aws_encryption_sdk.internal.crypto.data_keys import derive_data_encryption_key
2020

21+
pytestmark = [pytest.mark.unit, pytest.mark.local]
22+
2123

2224
@pytest.yield_fixture
2325
def patch_default_backend(mocker):

test/unit/test_crypto_elliptic_curve.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
)
2929
from .test_crypto import VALUES
3030

31+
pytestmark = [pytest.mark.unit, pytest.mark.local]
32+
3133

3234
@pytest.yield_fixture
3335
def patch_default_backend(mocker):

test/unit/test_crypto_encryption_decryptor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import aws_encryption_sdk.internal.crypto.encryption
1919
from aws_encryption_sdk.internal.crypto.encryption import decrypt, Decryptor
2020

21+
pytestmark = [pytest.mark.unit, pytest.mark.local]
22+
2123

2224
@pytest.yield_fixture
2325
def patch_default_backend(mocker):

test/unit/test_crypto_encryption_encryptor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from aws_encryption_sdk.internal.crypto.encryption import encrypt, Encryptor
2020
from aws_encryption_sdk.internal.structures import EncryptedData
2121

22+
pytestmark = [pytest.mark.unit, pytest.mark.local]
23+
2224

2325
@pytest.yield_fixture
2426
def patch_default_backend(mocker):

test/unit/test_crypto_prehashing_authenticator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import aws_encryption_sdk.internal.crypto.authentication
2121
from aws_encryption_sdk.internal.crypto.authentication import _PrehashingAuthenticator
2222

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2325

2426
@pytest.yield_fixture
2527
def patch_set_signature_type(mocker):

test/unit/test_crypto_wrapping_keys.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from aws_encryption_sdk.internal.structures import EncryptedData
2323
from .test_crypto import VALUES
2424

25+
pytestmark = [pytest.mark.unit, pytest.mark.local]
26+
2527

2628
@pytest.yield_fixture
2729
def patch_default_backend(mocker):

test/unit/test_defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
"""Test suite to verify calculated values in aws_encryption_sdk.internal.defaults"""
1414
import unittest
1515

16+
import pytest
17+
1618
import aws_encryption_sdk.internal.defaults
1719

20+
pytestmark = [pytest.mark.unit, pytest.mark.local]
21+
1822

1923
class TestDefaults(unittest.TestCase):
2024

test/unit/test_deserialize.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from cryptography.exceptions import InvalidTag
1818
from mock import MagicMock, patch, sentinel
19+
import pytest
1920
import six
2021

2122
from aws_encryption_sdk.exceptions import NotSupportedError, SerializationError, UnknownIdentityError
@@ -24,6 +25,8 @@
2425
from aws_encryption_sdk.internal.structures import EncryptedData
2526
from .test_values import VALUES
2627

28+
pytestmark = [pytest.mark.unit, pytest.mark.local]
29+
2730

2831
class TestDeserialize(unittest.TestCase):
2932

0 commit comments

Comments
 (0)