@@ -58,7 +58,10 @@ def mock_set_tracer_provider():
58
58
59
59
@pytest .fixture
60
60
def mock_otlp_exporter ():
61
- with mock .patch ("opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter" ) as mock_exporter :
61
+ with (
62
+ mock .patch ("strands.telemetry.tracer.HAS_OTEL_EXPORTER_MODULE" , True ),
63
+ mock .patch ("opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter" ) as mock_exporter ,
64
+ ):
62
65
yield mock_exporter
63
66
64
67
@@ -199,7 +202,11 @@ def test_initialize_tracer_with_otlp(
199
202
mock_resource .create .return_value = mock_resource_instance
200
203
201
204
# Initialize Tracer
202
- Tracer (otlp_endpoint = "http://test-endpoint" )
205
+ with (
206
+ mock .patch ("strands.telemetry.tracer.HAS_OTEL_EXPORTER_MODULE" , True ),
207
+ mock .patch ("strands.telemetry.tracer.OTLPSpanExporter" , mock_otlp_exporter ),
208
+ ):
209
+ Tracer (otlp_endpoint = "http://test-endpoint" )
203
210
204
211
# Verify the tracer provider was created with correct resource
205
212
mock_tracer_provider .assert_called_once_with (resource = mock_resource_instance )
@@ -508,7 +515,11 @@ def test_initialize_tracer_with_invalid_otlp_endpoint(
508
515
# This should not raise an exception, but should log an error
509
516
510
517
# Initialize Tracer
511
- Tracer (otlp_endpoint = "http://invalid-endpoint" )
518
+ with (
519
+ mock .patch ("strands.telemetry.tracer.HAS_OTEL_EXPORTER_MODULE" , True ),
520
+ mock .patch ("strands.telemetry.tracer.OTLPSpanExporter" , mock_otlp_exporter ),
521
+ ):
522
+ Tracer (otlp_endpoint = "http://invalid-endpoint" )
512
523
513
524
# Verify the tracer provider was created with correct resource
514
525
mock_tracer_provider .assert_called_once_with (resource = mock_resource_instance )
0 commit comments