Skip to content

Commit d7cf8b9

Browse files
lszinvrahul2393
andauthored
Fix: Cleanup after metric integration test (#1322)
Co-authored-by: rahul2393 <irahul@google.com>
1 parent 0098495 commit d7cf8b9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/unit/test_metrics.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,33 @@
2121
from google.cloud.spanner_v1.metrics.spanner_metrics_tracer_factory import (
2222
SpannerMetricsTracerFactory,
2323
)
24+
from opentelemetry import metrics
2425

2526
pytest.importorskip("opentelemetry")
2627
# Skip if semconv attributes are not present, as tracing wont' be enabled either
2728
# pytest.importorskip("opentelemetry.semconv.attributes.otel_attributes")
2829

2930

30-
def test_metrics_emission_with_failure_attempt(monkeypatch):
31+
@pytest.fixture(autouse=True)
32+
def patched_client(monkeypatch):
3133
monkeypatch.setenv("SPANNER_ENABLE_BUILTIN_METRICS", "true")
34+
metrics.set_meter_provider(metrics.NoOpMeterProvider())
3235

3336
# Remove the Tracer factory to avoid previously disabled factory polluting from other tests
3437
if SpannerMetricsTracerFactory._metrics_tracer_factory is not None:
3538
SpannerMetricsTracerFactory._metrics_tracer_factory = None
3639

3740
client = Client()
38-
instance = client.instance("test-instance")
41+
yield client
42+
43+
# Resetting
44+
metrics.set_meter_provider(metrics.NoOpMeterProvider())
45+
SpannerMetricsTracerFactory._metrics_tracer_factory = None
46+
SpannerMetricsTracerFactory.current_metrics_tracer = None
47+
48+
49+
def test_metrics_emission_with_failure_attempt(patched_client):
50+
instance = patched_client.instance("test-instance")
3951
database = instance.database("example-db")
4052
factory = SpannerMetricsTracerFactory()
4153

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy