From 786cb97cd8d4635e339735e025e7a87d48d1482b Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 1 Dec 2020 13:05:09 -0500 Subject: [PATCH] fix: avoid triggering global logging config Closes #332 --- google/cloud/storage/blob.py | 4 +++- tests/unit/test_blob.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 4c868b47c..ef7b88b46 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -122,6 +122,8 @@ _DEFAULT_CHUNKSIZE = 104857600 # 1024 * 1024 B * 100 = 100 MB _MAX_MULTIPART_SIZE = 8388608 # 8 MB +_logger = logging.getLogger(__name__) + class Blob(_PropertyMixin): """A wrapper around Cloud Storage's concept of an ``Object``. @@ -923,7 +925,7 @@ def _do_download( if checksum: msg = _CHUNKED_DOWNLOAD_CHECKSUM_MESSAGE.format(checksum) - logging.info(msg) + _logger.info(msg) if raw_download: klass = RawChunkedDownload diff --git a/tests/unit/test_blob.py b/tests/unit/test_blob.py index dd7f13a78..fc6eda60d 100644 --- a/tests/unit/test_blob.py +++ b/tests/unit/test_blob.py @@ -1115,7 +1115,7 @@ def test__do_download_w_chunks_w_custom_timeout(self): def test__do_download_w_chunks_w_checksum(self): from google.cloud.storage import blob as blob_module - with mock.patch("logging.info") as patch: + with mock.patch.object(blob_module._logger, "info") as patch: self._do_download_helper_w_chunks( w_range=False, raw_download=False, checksum="md5" ) @@ -1124,7 +1124,9 @@ def test__do_download_w_chunks_w_checksum(self): ) def test__do_download_w_chunks_wo_checksum(self): - with mock.patch("logging.info") as patch: + from google.cloud.storage import blob as blob_module + + with mock.patch.object(blob_module._logger, "info") as patch: self._do_download_helper_w_chunks( w_range=False, raw_download=False, checksum=None )