Pytest model of exceptions uses 'value' attribute instead of 'exception'.

This commit is contained in:
Matěj Cepl 2020-11-10 18:14:50 +01:00
commit 6d364dc7aa
9 changed files with 74 additions and 81 deletions

View file

@ -1,16 +1,14 @@
from __future__ import unicode_literals
# Ensure 'pytest.raises' context manager support for Python 2.6
import pytest
from moto.ec2 import ec2_backends
import boto
import boto3
from botocore.exceptions import ClientError
from boto.exception import EC2ResponseError
# Ensure 'pytest.raises' context manager support for Python 2.6
import pytest
import sure # noqa
from moto import mock_ec2_deprecated, mock_ec2
from boto.exception import EC2ResponseError
from botocore.exceptions import ClientError
from moto import mock_ec2, mock_ec2_deprecated
from moto.ec2 import ec2_backends
from moto.ec2.models import OWNER_ID
from moto.kms import mock_kms
@ -920,12 +918,12 @@ def test_search_for_many_snapshots():
@mock_ec2
def test_create_unencrypted_volume_with_kms_key_fails():
resource = boto3.resource("ec2", region_name="us-east-1")
with assert_raises(ClientError) as ex:
with pytest.raises(ClientError) as ex:
resource.create_volume(
AvailabilityZone="us-east-1a", Encrypted=False, KmsKeyId="key", Size=10
)
ex.exception.response["Error"]["Code"].should.equal("InvalidParameterDependency")
ex.exception.response["Error"]["Message"].should.contain("KmsKeyId")
ex.value.response["Error"]["Code"].should.equal("InvalidParameterDependency")
ex.value.response["Error"]["Message"].should.contain("KmsKeyId")
@mock_kms
@ -933,9 +931,9 @@ def test_create_unencrypted_volume_with_kms_key_fails():
def test_create_encrypted_volume_without_kms_key_should_use_default_key():
kms = boto3.client("kms", region_name="us-east-1")
# Default master key for EBS does not exist until needed.
with assert_raises(ClientError) as ex:
with pytest.raises(ClientError) as ex:
kms.describe_key(KeyId="alias/aws/ebs")
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
ex.value.response["Error"]["Code"].should.equal("NotFoundException")
# Creating an encrypted volume should create (and use) the default key.
resource = boto3.resource("ec2", region_name="us-east-1")
volume = resource.create_volume(

View file

@ -1,16 +1,16 @@
from __future__ import unicode_literals
import random
import boto
import boto3
import boto.vpc
# Ensure 'pytest.raises' context manager support for Python 2.6
import pytest
import boto3
import boto
import boto.vpc
from boto.exception import EC2ResponseError
from botocore.exceptions import ParamValidationError, ClientError
import sure # noqa
import random
from boto.exception import EC2ResponseError
from botocore.exceptions import ClientError, ParamValidationError
from moto import mock_ec2, mock_ec2_deprecated
@ -426,7 +426,7 @@ def test_create_subnet_with_invalid_cidr_range_multiple_vpc_cidr_blocks():
vpc.is_default.shouldnt.be.ok
subnet_cidr_block = "10.2.0.0/20"
with assert_raises(ClientError) as ex:
with pytest.raises(ClientError) as ex:
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock=subnet_cidr_block)
str(ex.exception).should.equal(
"An error occurred (InvalidSubnet.Range) when calling the CreateSubnet "