diff --git a/tests/opentelemetry-test-utils/src/opentelemetry/test/test_base.py b/tests/opentelemetry-test-utils/src/opentelemetry/test/test_base.py index f9ac2dfc193..456bd1413f3 100644 --- a/tests/opentelemetry-test-utils/src/opentelemetry/test/test_base.py +++ b/tests/opentelemetry-test-utils/src/opentelemetry/test/test_base.py @@ -144,8 +144,9 @@ def disable_logging(highest_level=logging.CRITICAL): logging.disable(logging.NOTSET) def get_sorted_metrics(self): + metrics_data = self.memory_metrics_reader.get_metrics_data() resource_metrics = ( - self.memory_metrics_reader.get_metrics_data().resource_metrics + metrics_data.resource_metrics if metrics_data else [] ) all_metrics = [] diff --git a/tests/opentelemetry-test-utils/tests/test_base.py b/tests/opentelemetry-test-utils/tests/test_base.py new file mode 100644 index 00000000000..92b83b9b34c --- /dev/null +++ b/tests/opentelemetry-test-utils/tests/test_base.py @@ -0,0 +1,21 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from opentelemetry.test.test_base import TestBase + + +class TestBaseTestCase(TestBase): + def test_get_sorted_metrics_works_without_metrics(self): + metrics = self.get_sorted_metrics() + self.assertEqual(metrics, [])