aws / aws/serverless-application-model

1.92.0: pytest fails in 6 units

Open
#3,677 2 comments 0 reactions 0 assignees View on GitHub
contributors/good-first-issue contributors/welcome
Dominant language
Python
Stars
9.6k
Forks
2.5k
Avg merge
1d 11h
Merged PRs (30d)
7

Description

### Description
Looks like pytest fails in 6 units.

### Steps to reproduce
I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.
- `python3 -sBm build -w --no-isolation`
- because I'm calling `build` with `--no-isolation` I'm using during all processes only locally installed modules
- install .whl file in using `installer` module
- run pytest with $PYTHONPATH pointing to sitearch and sitelib inside
- build is performed in env which is *`cut off from access to the public network`* (pytest is executed with `-m "not network"`)

### Observed result

Here is pytest output:

```console
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-aws-sam-translator-1.92.0-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-aws-sam-translator-1.92.0-2.fc37.x86_64/usr/lib/python3.10/site-packages
+ /usr/bin/pytest -ra -m 'not network' --ignore tests/bin/test_public_interface.py
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.2, pluggy-1.5.0
rootdir: /home/tkloczko/rpmbuild/BUILD/serverless-application-model-1.92.0
configfile: pytest.ini
testpaths: tests
collected 3984 items

tests/feature_toggle/test_dialup.py .............. [ 0%]
tests/feature_toggle/test_feature_toggle.py ..................................... [ 1%]
tests/internal/test_deprecation_control.py . [ 1%]
tests/intrinsics/test_actions.py ............................................................................ [ 3%]
tests/intrinsics/test_resolver.py ..................... [ 3%]
tests/intrinsics/test_resource_refs.py ............ [ 4%]
tests/metrics/test_method_decorator.py ......... [ 4%]
tests/metrics/test_metrics.py ................. [ 4%]
tests/model/api/test_api_generator.py .... [ 4%]
tests/model/api/test_http_api_generator.py ............................ [ 5%]
tests/model/connector_profiles/test_profile.py ............. [ 5%]
tests/model/eventsources/test_api_event_source.py ...... [ 5%]
tests/model/eventsources/test_cloudwatch_event_source.py .. [ 6%]
tests/model/eventsources/test_cloudwatchlogs_event_source.py .... [ 6%]
tests/model/eventsources/test_documentdb_event_source.py ........... [ 6%]
tests/model/eventsources/test_eventbridge_rule_source.py ................... [ 6%]
tests/model/eventsources/test_mq_event_source.py ....... [ 7%]
tests/model/eventsources/test_msk_event_source.py ... [ 7%]
tests/model/eventsources/test_schedule_event_source.py ................ [ 7%]
tests/model/eventsources/test_schedulev2_event_source.py ........................... [ 8%]
tests/model/eventsources/test_self_managed_kafka_event_source.py ................... [ 8%]
tests/model/eventsources/test_sns_event_source.py ........ [ 8%]
tests/model/stepfunctions/test_api_event.py ...... [ 9%]
tests/model/stepfunctions/test_cloudwatchevents_event.py ............ [ 9%]
tests/model/stepfunctions/test_eventbridge_rule_source.py .... [ 9%]
tests/model/stepfunctions/test_schedule_event.py ................... [ 9%]
tests/model/stepfunctions/test_state_machine_generator.py ............... [ 10%]
tests/model/tags/test_resource_tagging.py ... [ 10%]
tests/model/test_api.py ............. [ 10%]
tests/model/test_api_v2.py ................. [ 11%]
tests/model/test_exceptions.py ...... [ 11%]
tests/model/test_resource.py .. [ 11%]
tests/model/test_resource_policies.py ...................................... [ 12%]
tests/model/test_resource_validator.py ...... [ 12%]
tests/model/test_sam_resources.py ................................................ [ 13%]
tests/openapi/test_openapi.py .............................................. [ 14%]
tests/parser/test_parser.py ..... [ 14%]
tests/plugins/api/test_default_definition_body_plugin.py ... [ 14%]
tests/plugins/api/test_implicit_api_plugin.py ............................................. [ 16%]
tests/plugins/application/test_serverless_app_plugin.py ..............FFFF......F [ 16%]
tests/plugins/globals/test_globals.py ............................................ [ 17%]
tests/plugins/globals/test_globals_plugin.py ... [ 17%]
tests/plugins/policies/test_policy_templates_plugin.py ........... [ 18%]
tests/policy_template_processor/test_processor.py .................. [ 18%]
tests/policy_template_processor/test_schema.py ............... [ 19%]
tests/policy_template_processor/test_template.py ............... [ 19%]
tests/schema/test_validate_schema.py ................................................................................................................................................ [ 23%]
..................................................................................................................................................................................... [ 27%]
..................................................................................................................................................................................... [ 32%]
.......................................................................................................................... [ 35%]
tests/sdk/test_parameter.py ............ [ 35%]
tests/sdk/test_resource.py ....... [ 35%]
tests/sdk/test_template.py ............ [ 35%]
tests/swagger/test_swagger.py ........................................................................................................ [ 38%]
tests/test_import.py ............................................................................................................................................................ [ 42%]
tests/test_intrinsics.py ............................ [ 43%]
tests/test_model.py ............................. [ 43%]
tests/test_plugins.py .......................... [ 44%]
tests/test_types.py ............ [ 44%]
tests/translator/model/preferences/test_deployment_preference.py ........ [ 45%]
tests/translator/model/preferences/test_deployment_preference_collection.py .......................... [ 45%]
tests/translator/model/test_update_policy.py .. [ 45%]
tests/translator/test_api_resource.py .... [ 45%]
tests/translator/test_arn_generator.py ............ [ 46%]
tests/translator/test_function_resources.py ............................... [ 46%]
tests/translator/test_logical_id_generator.py ................. [ 47%]
tests/translator/test_managed_policies_translator.py . [ 47%]
tests/translator/test_resource_level_attributes.py ........................................................................................................................... [ 50%]
tests/translator/test_translator.py ................................................................................................................................................. [ 54%]
..................................................................................................................................................................................... [ 58%]
..................................................................................................................................................................................... [ 63%]
..................................................................................................................................................................................... [ 67%]
..................................................................................................................................................................................... [ 72%]
..................................................................................................................................................................................... [ 76%]
..................................................................................................................................................................................... [ 81%]
..................................................................................................................................................................................... [ 85%]
..................................................................................................................................................................................... [ 90%]
..................................................................................................................................................................................... [ 95%]
.................................................................................. [ 97%]
tests/unit/model/preferences/test_deployment_preference_collection.py ..... [ 97%]
tests/unit/test_region_configuration.py .....F.......... [ 97%]
tests/unit/translator/test_arn_generator.py .............. [ 97%]
tests/utils/test_dynamic_references.py ........ [ 98%]
tests/utils/test_py27hash_fix.py ................................................................... [ 99%]
tests/utils/test_utils.py ....... [100%]

========================================================================================= FAILURES ==========================================================================================
__________________________________________________ TestServerlessAppPlugin_on_before_transform_template_translate.test_sar_success_one_app __________________________________________________

self =
SamTemplateMock =

@patch("samtranslator.plugins.application.serverless_app_plugin.SamTemplate")
def test_sar_success_one_app(self, SamTemplateMock):
template_dict = {"a": "b"}
app_resources = [
("id1", ApplicationResource(app_id="id1", semver="1.0.0", location=True)),
]

sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.iterate = Mock()
sam_template.iterate.return_value = app_resources

client = Mock()
client.create_cloud_formation_template = Mock()
client.create_cloud_formation_template.return_value = {"TemplateUrl": "/URL", "Status": STATUS_ACTIVE}
self.plugin = ServerlessAppPlugin(sar_client=client)
self.plugin._can_process_application = Mock()
self.plugin._can_process_application.return_value = True
> self.plugin.on_before_transform_template(template_dict)

tests/plugins/application/test_serverless_app_plugin.py:311:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
samtranslator/metrics/method_decorator.py:117: in wrapper_cw_timer
exec_result = func(*args, **kwargs)
samtranslator/plugins/application/serverless_app_plugin.py:150: in on_before_transform_template
if not RegionConfiguration.is_service_supported("serverlessrepo"): # type: ignore[no-untyped-call]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = , service = 'serverlessrepo', region = None

@classmethod
def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-def]
"""
Not all services are supported in all regions. This method returns whether a given
service is supported in a given region. If no region is specified, the current region
(as identified by boto3) is used.
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/

:param service: service code (string used to obtain a boto3 client for the service)
:param region: region identifier (e.g., us-east-1)
:return: True, if the service is supported in the region
"""

# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
region = session.region_name

# need to handle when region is None so that it won't break
if region is None:
if ArnGenerator.BOTO_SESSION_REGION_NAME is not None:
region = ArnGenerator.BOTO_SESSION_REGION_NAME
else:
> raise NoRegionFound("AWS Region cannot be found")
E samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found

samtranslator/region_configuration.py:50: NoRegionFound
_________________________________________ TestServerlessAppPlugin_on_before_transform_template_translate.test_sar_throttling_doesnt_stop_processing _________________________________________

self =
SamTemplateMock =

@patch("samtranslator.plugins.application.serverless_app_plugin.SamTemplate")
def test_sar_throttling_doesnt_stop_processing(self, SamTemplateMock):
client = Mock()
client.create_cloud_formation_template = Mock()
client.create_cloud_formation_template.side_effect = ClientError(
{"Error": {"Code": "TooManyRequestsException"}}, "CreateCloudFormationTemplate"
)

app_resources = [
("id1", ApplicationResource(app_id="id1", semver="1.0.0", location=True)),
]

sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.iterate = Mock()
sam_template.iterate.return_value = app_resources

self.plugin = ServerlessAppPlugin(sar_client=client)
self.plugin._can_process_application = Mock()
self.plugin._can_process_application.return_value = True
self.plugin._get_sleep_time_sec = Mock()
self.plugin._get_sleep_time_sec.return_value = 0.02
self.plugin.TEMPLATE_WAIT_TIMEOUT_SECONDS = 1.0

> self.plugin.on_before_transform_template({})

tests/plugins/application/test_serverless_app_plugin.py:261:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
samtranslator/metrics/method_decorator.py:117: in wrapper_cw_timer
exec_result = func(*args, **kwargs)
samtranslator/plugins/application/serverless_app_plugin.py:150: in on_before_transform_template
if not RegionConfiguration.is_service_supported("serverlessrepo"): # type: ignore[no-untyped-call]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = , service = 'serverlessrepo', region = None

@classmethod
def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-def]
"""
Not all services are supported in all regions. This method returns whether a given
service is supported in a given region. If no region is specified, the current region
(as identified by boto3) is used.
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/

:param service: service code (string used to obtain a boto3 client for the service)
:param region: region identifier (e.g., us-east-1)
:return: True, if the service is supported in the region
"""

# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
region = session.region_name

# need to handle when region is None so that it won't break
if region is None:
if ArnGenerator.BOTO_SESSION_REGION_NAME is not None:
region = ArnGenerator.BOTO_SESSION_REGION_NAME
else:
> raise NoRegionFound("AWS Region cannot be found")
E samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found

samtranslator/region_configuration.py:50: NoRegionFound
_______________________________________________ TestServerlessAppPlugin_on_before_transform_template_translate.test_sleep_between_sar_checks ________________________________________________

self =
SamTemplateMock =

@patch("samtranslator.plugins.application.serverless_app_plugin.SamTemplate")
def test_sleep_between_sar_checks(self, SamTemplateMock):
template_dict = {"a": "b"}
client = Mock()

app_resources = [
("id1", ApplicationResource(app_id="id1", semver="1.0.0", location=True)),
]

sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.iterate = Mock()
sam_template.iterate.return_value = app_resources
client.create_cloud_formation_template = Mock()
client.create_cloud_formation_template.side_effect = [
ClientError({"Error": {"Code": "TooManyRequestsException"}}, "CreateCloudFormationTemplate"),
{"TemplateUrl": "/URL", "Status": STATUS_ACTIVE},
]
self.plugin._can_process_application = Mock()
self.plugin._can_process_application.return_value = True
self.plugin = ServerlessAppPlugin(sar_client=client, wait_for_template_active_status=True, validate_only=False)
self.plugin._get_sleep_time_sec = Mock()
self.plugin._get_sleep_time_sec.return_value = 0.001
> self.plugin.on_before_transform_template(template_dict)

tests/plugins/application/test_serverless_app_plugin.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
samtranslator/metrics/method_decorator.py:117: in wrapper_cw_timer
exec_result = func(*args, **kwargs)
samtranslator/plugins/application/serverless_app_plugin.py:150: in on_before_transform_template
if not RegionConfiguration.is_service_supported("serverlessrepo"): # type: ignore[no-untyped-call]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = , service = 'serverlessrepo', region = None

@classmethod
def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-def]
"""
Not all services are supported in all regions. This method returns whether a given
service is supported in a given region. If no region is specified, the current region
(as identified by boto3) is used.
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/

:param service: service code (string used to obtain a boto3 client for the service)
:param region: region identifier (e.g., us-east-1)
:return: True, if the service is supported in the region
"""

# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
region = session.region_name

# need to handle when region is None so that it won't break
if region is None:
if ArnGenerator.BOTO_SESSION_REGION_NAME is not None:
region = ArnGenerator.BOTO_SESSION_REGION_NAME
else:
> raise NoRegionFound("AWS Region cannot be found")
E samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found

samtranslator/region_configuration.py:50: NoRegionFound
_________________________________________ TestServerlessAppPlugin_on_before_transform_template_translate.test_unexpected_sar_error_stops_processing _________________________________________

self =
SamTemplateMock =

@patch("samtranslator.plugins.application.serverless_app_plugin.SamTemplate")
def test_unexpected_sar_error_stops_processing(self, SamTemplateMock):
template_dict = {"a": "b"}
app_resources = [
("id1", ApplicationResource(app_id="id1", semver="1.0.0", location=True)),
]

sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.iterate = Mock()
sam_template.iterate.return_value = app_resources

client = Mock()
client.create_cloud_formation_template.side_effect = ClientError(
{"Error": {"Code": "BadBadError"}}, "CreateCloudFormationTemplate"
)
self.plugin = ServerlessAppPlugin(sar_client=client)
self.plugin._can_process_application = Mock()
self.plugin._can_process_application.return_value = True

with self.assertRaises(ClientError):
> self.plugin.on_before_transform_template(template_dict)

tests/plugins/application/test_serverless_app_plugin.py:291:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
samtranslator/metrics/method_decorator.py:117: in wrapper_cw_timer
exec_result = func(*args, **kwargs)
samtranslator/plugins/application/serverless_app_plugin.py:150: in on_before_transform_template
if not RegionConfiguration.is_service_supported("serverlessrepo"): # type: ignore[no-untyped-call]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

@classmethod
def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-def]
"""
Not all services are supported in all regions. This method returns whether a given
service is supported in a given region. If no region is specified, the current region
(as identified by boto3) is used.
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/

:param service: service code (string used to obtain a boto3 client for the service)
:param region: region identifier (e.g., us-east-1)
:return: True, if the service is supported in the region
"""

# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
region = session.region_name

# need to handle when region is None so that it won't break
if region is None:
if ArnGenerator.BOTO_SESSION_REGION_NAME is not None:
region = ArnGenerator.BOTO_SESSION_REGION_NAME
else:
> raise NoRegionFound("AWS Region cannot be found")
E samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found

samtranslator/region_configuration.py:50: NoRegionFound
___________________________________ TestServerlessAppPlugin_on_before_and_on_after_transform_template.test_time_limit_exceeds_between_combined_sar_calls ____________________________________

self =
SamTemplateMock =

@patch("samtranslator.plugins.application.serverless_app_plugin.SamTemplate")
def test_time_limit_exceeds_between_combined_sar_calls(self, SamTemplateMock):
template_dict = {"a": "b"}
app_resources = [
("id1", ApplicationResource(app_id="id1", semver="1.0.0", location=True)),
]

sam_template = Mock()
SamTemplateMock.return_value = sam_template
sam_template.iterate = Mock()
sam_template.iterate.return_value = app_resources

client = Mock()
client.get_cloud_formation_template = Mock()
client.get_cloud_formation_template.side_effect = [
ClientError({"Error": {"Code": "TooManyRequestsException"}}, "GetCloudFormationTemplate"),
{"Status": STATUS_ACTIVE},
]
client.create_cloud_formation_template = Mock()
client.create_cloud_formation_template.side_effect = [
ClientError({"Error": {"Code": "TooManyRequestsException"}}, "CreateCloudFormationTemplate"),
{"TemplateUrl": "/URL", "Status": STATUS_ACTIVE},
]
plugin = ServerlessAppPlugin(sar_client=client, wait_for_template_active_status=True, validate_only=False)
plugin._get_sleep_time_sec = Mock()
plugin._get_sleep_time_sec.return_value = 0.04
plugin._in_progress_templates = [("appid", "template"), ("appid2", "template2")]
plugin.TEMPLATE_WAIT_TIMEOUT_SECONDS = 0.08

> plugin.on_before_transform_template(template_dict)

tests/plugins/application/test_serverless_app_plugin.py:487:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
samtranslator/metrics/method_decorator.py:117: in wrapper_cw_timer
exec_result = func(*args, **kwargs)
samtranslator/plugins/application/serverless_app_plugin.py:150: in on_before_transform_template
if not RegionConfiguration.is_service_supported("serverlessrepo"): # type: ignore[no-untyped-call]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = , service = 'serverlessrepo', region = None

@classmethod
def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-def]
"""
Not all services are supported in all regions. This method returns whether a given
service is supported in a given region. If no region is specified, the current region
(as identified by boto3) is used.
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/

:param service: service code (string used to obtain a boto3 client for the service)
:param region: region identifier (e.g., us-east-1)
:return: True, if the service is supported in the region
"""

# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
region = session.region_name

# need to handle when region is None so that it won't break
if region is None:
if ArnGenerator.BOTO_SESSION_REGION_NAME is not None:
region = ArnGenerator.BOTO_SESSION_REGION_NAME
else:
> raise NoRegionFound("AWS Region cannot be found")
E samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found

samtranslator/region_configuration.py:50: NoRegionFound
_____________________________________________________________ TestRegionConfiguration.test_is_service_supported_positive_4_ec2 ______________________________________________________________

a = (,), kw = {}

@wraps(func)
def standalone_func(*a, **kw):
> return func(*(a + p.args), **p.kwargs, **kw)

/usr/lib/python3.10/site-packages/parameterized/parameterized.py:544:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/unit/test_region_configuration.py:46: in test_is_service_supported_positive
self.assertTrue(RegionConfiguration.is_service_supported(service, region))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = , service = 'ec2', region = None

@classmethod
def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-def]
"""
Not all services are supported in all regions. This method returns whether a given
service is supported in a given region. If no region is specified, the current region
(as identified by boto3) is used.
https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/

:param service: service code (string used to obtain a boto3 client for the service)
:param region: region identifier (e.g., us-east-1)
:return: True, if the service is supported in the region
"""

# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
region = session.region_name

# need to handle when region is None so that it won't break
if region is None:
if ArnGenerator.BOTO_SESSION_REGION_NAME is not None:
region = ArnGenerator.BOTO_SESSION_REGION_NAME
else:
> raise NoRegionFound("AWS Region cannot be found")
E samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found

samtranslator/region_configuration.py:50: NoRegionFound
================================================================================== short test summary info ==================================================================================
FAILED tests/plugins/application/test_serverless_app_plugin.py::TestServerlessAppPlugin_on_before_transform_template_translate::test_sar_success_one_app - samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found
FAILED tests/plugins/application/test_serverless_app_plugin.py::TestServerlessAppPlugin_on_before_transform_template_translate::test_sar_throttling_doesnt_stop_processing - samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found
FAILED tests/plugins/application/test_serverless_app_plugin.py::TestServerlessAppPlugin_on_before_transform_template_translate::test_sleep_between_sar_checks - samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found
FAILED tests/plugins/application/test_serverless_app_plugin.py::TestServerlessAppPlugin_on_before_transform_template_translate::test_unexpected_sar_error_stops_processing - samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found
FAILED tests/plugins/application/test_serverless_app_plugin.py::TestServerlessAppPlugin_on_before_and_on_after_transform_template::test_time_limit_exceeds_between_combined_sar_calls - samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found
FAILED tests/unit/test_region_configuration.py::TestRegionConfiguration::test_is_service_supported_positive_4_ec2 - samtranslator.translator.arn_generator.NoRegionFound: AWS Region cannot be found
======================================================================== 6 failed, 3978 passed in 339.30s (0:05:39) =========================================================================
```

### Expected result
pytest should not fail.

### Additional environment details

List of installed modules in build env:

```console
Package Version
----------------------------- -----------
alabaster 0.7.16
annotated-types 0.7.0
attrs 24.2.0
babel 2.16.0
boto3 1.35.56
botocore 1.35.56
build 1.2.2.post1
charset-normalizer 3.4.0
defusedxml 0.7.1
distro 1.9.0
docutils 0.21.2
exceptiongroup 1.1.3
imagesize 1.4.1
importlib_metadata 8.5.0
iniconfig 2.0.0
installer 0.7.0
Jinja2 3.1.4
jmespath 1.0.1
jsonschema 4.20.0
jsonschema-specifications 2024.10.1
MarkupSafe 3.0.2
packaging 24.0
parameterized 0.9.0
pluggy 1.5.0
pydantic 2.9.2
pydantic_core 2.23.4
Pygments 2.18.0
pyproject_hooks 1.2.0
pytest 8.2.2
python-dateutil 2.9.0.post0
PyYAML 6.0.2
referencing 0.32.0
requests 2.32.3
rpds-py 0.21.0
s3transfer 0.10.3
setuptools 75.1.0
snowballstemmer 2.2.0
Sphinx 8.1.3
sphinxcontrib-applehelp 2.0.0
sphinxcontrib-devhelp 1.0.6
sphinxcontrib-htmlhelp 2.1.0
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 2.0.0
sphinxcontrib-serializinghtml 2.0.0
tokenize_rt 6.1.0
tomli 2.0.1
typing_extensions 4.12.2
urllib3 2.2.2
wheel 0.45.0
zipp 3.20.2
```

Please let me know if you need more details or want me to perform some diagnostics.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.