Skip to content

Commit 2e7d2e9

Browse files
committed
Fix broken test
1 parent 59bb054 commit 2e7d2e9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

exporter/exporter-credential-providers/gcp-credential-provider/tests/test_credential_provider.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
from os import environ
1515
from unittest import TestCase
16-
from unittest.mock import patch
16+
from unittest.mock import MagicMock, patch
1717

1818
from google.auth.transport.requests import AuthorizedSession
1919

@@ -27,16 +27,21 @@
2727

2828

2929
class TestOTLPTraceAutoInstrumentGcpCredential(TestCase):
30+
@patch("google.auth.default")
3031
@patch.dict(
3132
environ,
3233
{
3334
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER: "gcp_http_credentials",
3435
_OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER: "gcp_grpc_credentials",
3536
},
3637
)
37-
def test_loads_otlp_exporters_with_google_creds(self): # pylint: disable=no-self-use
38+
def test_loads_otlp_exporters_with_google_creds(self, mock_default): # pylint: disable=no-self-use
3839
"""Test that OTel configuration internals can load the credentials from entrypoint by
3940
name"""
40-
41+
mock_credentials = MagicMock()
42+
mock_credentials.project_id = "test-project"
43+
mock_default.return_value = (mock_credentials, "test-project")
4144
http_exporter = OTLPSpanExporter()
4245
assert isinstance(http_exporter._session, AuthorizedSession)
46+
# Assert that google.auth.default was called
47+
mock_default.assert_called_once()

0 commit comments

Comments
 (0)