diff --git a/tests/functional/test_metrics.py b/tests/functional/test_metrics.py index 4dbefd34603..6cf33a3eaa4 100644 --- a/tests/functional/test_metrics.py +++ b/tests/functional/test_metrics.py @@ -319,9 +319,20 @@ def test_schema_no_metrics(service, namespace): my_metrics.serialize_metric_set() -def test_exceed_number_of_dimensions(metric, namespace, monkeypatch): - # GIVEN we we have more dimensions than CloudWatch supports - # and that service dimension is injected like a user-defined dimension (N+1) +def test_exceed_number_of_dimensions(metric, namespace): + # GIVEN we have more dimensions than CloudWatch supports + dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(11)] + + # WHEN we attempt to serialize them into a valid EMF object + # THEN it should fail validation and raise SchemaValidationError + with pytest.raises(SchemaValidationError, match="Maximum number of dimensions exceeded.*"): + with single_metric(**metric, namespace=namespace) as my_metric: + for dimension in dimensions: + my_metric.add_dimension(**dimension) + + +def test_exceed_number_of_dimensions_with_service(metric, namespace, monkeypatch): + # GIVEN we have service set and add more dimensions than CloudWatch supports (N+1) monkeypatch.setenv("POWERTOOLS_SERVICE_NAME", "test_service") dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(9)]