Skip to content

Commit 95efc91

Browse files
ansanpermattsb42-aws
authored andcommitted
Migrate "test/unit/test_providers_kms_master_key_provider.py" from unittest to pytest (#122)
* Migrating unit/test_deserialize.py from unittest from pytest * Migrate unit/test_provides_kms_master_key.py from unittest to pytest * Migrated unit/test/_providers_kms_master_key_provider.py from unittest to pytest * Removed unit tests not corresponding to this branch * Added yield and tearDown to apply_fixtures function * Removed unused import
1 parent ee1cb69 commit 95efc91

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

test/unit/test_providers_kms_master_key_provider.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite from aws_encryption_sdk.key_providers.kms.KMSMasterKeyProvider"""
14-
import unittest
15-
1614
import botocore.client
1715
import pytest
18-
import six
1916
from mock import ANY, MagicMock, call, patch, sentinel
2017

2118
from aws_encryption_sdk.exceptions import UnknownRegionError
@@ -32,8 +29,9 @@ def test_init_with_regionless_key_ids_and_region_names():
3229
assert provider.master_key("alias/key_1").config.client.meta.region_name == region_names[0]
3330

3431

35-
class TestKMSMasterKeyProvider(unittest.TestCase):
36-
def setUp(self):
32+
class TestKMSMasterKeyProvider(object):
33+
@pytest.fixture(autouse=True)
34+
def apply_fixtures(self):
3735
self.mock_botocore_session_patcher = patch("aws_encryption_sdk.key_providers.kms.botocore.session.Session")
3836
self.mock_botocore_session = self.mock_botocore_session_patcher.start()
3937
self.mock_boto3_session_patcher = patch("aws_encryption_sdk.key_providers.kms.boto3.session.Session")
@@ -43,8 +41,8 @@ def setUp(self):
4341
self.mock_boto3_client_instance = MagicMock()
4442
self.mock_boto3_client_instance.__class__ = botocore.client.BaseClient
4543
self.mock_boto3_session_instance.client.return_value = self.mock_boto3_client_instance
46-
47-
def tearDown(self):
44+
yield
45+
# Run tearDown
4846
self.mock_botocore_session_patcher.stop()
4947
self.mock_boto3_session_patcher.stop()
5048

@@ -130,10 +128,9 @@ def test_client_no_region_name_with_default(self, mock_add_client):
130128

131129
def test_client_no_region_name_without_default(self):
132130
test = KMSMasterKeyProvider()
133-
with six.assertRaisesRegex(
134-
self, UnknownRegionError, "No default region found and no region determinable from key id: *"
135-
):
131+
with pytest.raises(UnknownRegionError) as excinfo:
136132
test._client("")
133+
excinfo.match("No default region found and no region determinable from key id: *")
137134

138135
@patch("aws_encryption_sdk.key_providers.kms.KMSMasterKeyProvider._client")
139136
def test_new_master_key(self, mock_client):

0 commit comments

Comments
 (0)