Skip to content

Commit 258d98c

Browse files
committed
test: disable Spanner built-in Cloud Monitoring metrics in tests
The Spanner client's built-in metrics exporter runs a background thread that flushes to Cloud Monitoring. Without GCP credentials it fails to authenticate and logs the failure during interpreter teardown — after the safe-logging handlers are closed — surfacing as "Failed to export metrics to Cloud Monitoring" and "I/O operation on closed file", which intermittently failed the test job on a non-zero exit (seen on 3.9/3.10 while 3.11-3.14 passed with the same code). Set SPANNER_DISABLE_BUILTIN_METRICS=true at conftest import (before any Spanner client is created) so the exporter thread is never started. The emulator does not need these metrics.
1 parent f03d168 commit 258d98c

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import logging
3+
import os
34
from collections.abc import Generator
45
from typing import TYPE_CHECKING
56

@@ -16,6 +17,14 @@
1617
if TYPE_CHECKING:
1718
pass
1819

20+
# Disable Google Cloud Spanner's built-in Cloud Monitoring metrics export before any Spanner
21+
# client is created. Without GCP credentials its background exporter thread fails to
22+
# authenticate and logs errors during interpreter teardown (after the safe-logging handlers
23+
# are closed), which surfaces as "Failed to export metrics to Cloud Monitoring" /
24+
# "I/O operation on closed file" and can fail the job on a non-zero exit. The emulator used in
25+
# tests does not need these metrics.
26+
os.environ.setdefault("SPANNER_DISABLE_BUILTIN_METRICS", "true")
27+
1928
pytest_plugins = [
2029
"pytest_databases.docker",
2130
"pytest_databases.docker.rustfs",

0 commit comments

Comments
 (0)