From 43dfa4765b87d4c8e01b9f7a1b6e23d2df14e190 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 26 Jan 2022 12:35:14 -0600 Subject: [PATCH] Fix log message Fixes #2413 --- .../src/opentelemetry/sdk/_metrics/__init__.py | 2 +- opentelemetry-sdk/tests/metrics/test_metrics.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py index 705e814d695..4f0d5d141aa 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/__init__.py @@ -205,7 +205,7 @@ def shutdown(self): if not metric_reader_result: _logger.warning( - "MetricReader {metric_reader} failed to shutdown" + "MetricReader %s failed to shutdown", metric_reader ) overall_result = overall_result and metric_reader_result diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index 3510e9691e7..3126535a906 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -15,7 +15,7 @@ from logging import WARNING from unittest import TestCase -from unittest.mock import Mock, patch +from unittest.mock import MagicMock, Mock, patch from opentelemetry.sdk._metrics import Meter, MeterProvider from opentelemetry.sdk._metrics.instrument import ( @@ -92,14 +92,24 @@ def test_get_meter_duplicate(self): def test_shutdown(self): - mock_metric_reader_0 = Mock(**{"shutdown.return_value": False}) + mock_metric_reader_0 = MagicMock( + **{ + "shutdown.return_value": False, + "__str__.return_value": "mock_metric_reader_0", + } + ) mock_metric_reader_1 = Mock(**{"shutdown.return_value": True}) meter_provider = MeterProvider( metric_readers=[mock_metric_reader_0, mock_metric_reader_1] ) - self.assertFalse(meter_provider.shutdown()) + with self.assertLogs(level=WARNING) as log: + self.assertFalse(meter_provider.shutdown()) + self.assertEqual( + log.records[0].getMessage(), + "MetricReader mock_metric_reader_0 failed to shutdown", + ) mock_metric_reader_0.shutdown.assert_called_once() mock_metric_reader_1.shutdown.assert_called_once()