diff --git a/tests/providers/google/cloud/utils/test_credentials_provider.py b/tests/providers/google/cloud/utils/test_credentials_provider.py index 7a67af9a0e080..58e97d3926e26 100644 --- a/tests/providers/google/cloud/utils/test_credentials_provider.py +++ b/tests/providers/google/cloud/utils/test_credentials_provider.py @@ -17,6 +17,7 @@ from __future__ import annotations import json +import logging import os import re import unittest @@ -327,22 +328,28 @@ def test_get_credentials_and_project_id_with_mutually_exclusive_configuration( ) def test_disable_logging(self, mock_default, mock_info, mock_file): # assert not logs - with pytest.raises(AssertionError), self.assertLogs(level="DEBUG"): + with self.assertLogs(level="DEBUG") as logs: + logging.debug('nothing') get_credentials_and_project_id(disable_logging=True) + assert logs.output == ['DEBUG:root:nothing'] - # assert not logs - with pytest.raises(AssertionError), self.assertLogs(level="DEBUG"): + # assert no debug logs emitted from get_credentials_and_project_id + with self.assertLogs(level="DEBUG") as logs: + logging.debug('nothing') get_credentials_and_project_id( keyfile_dict={'private_key': 'PRIVATE_KEY'}, disable_logging=True, ) + assert logs.output == ['DEBUG:root:nothing'] - # assert not logs - with pytest.raises(AssertionError), self.assertLogs(level="DEBUG"): + # assert no debug logs emitted from get_credentials_and_project_id + with self.assertLogs(level="DEBUG") as logs: + logging.debug('nothing') get_credentials_and_project_id( key_path='KEY.json', disable_logging=True, ) + assert logs.output == ['DEBUG:root:nothing'] class TestGetScopes(unittest.TestCase):