test(spanner): revert noxfile changes and disable AFE server timing in conftest - #17980
test(spanner): revert noxfile changes and disable AFE server timing in conftest#17980sakthivelmanii wants to merge 2 commits into
Conversation
…n conftest Reverts the edits to packages/google-cloud-spanner/noxfile.py from PR #17970 to restore compliance with owlbot/librarian autogeneration and fix issue #17974. Disables AFE server timing in unit tests directly inside tests/unit/conftest.py by setting SPANNER_DISABLE_AFE_SERVER_TIMING="true" and _helpers.ENABLE_AFE_SERVER_TIMING = False. This ensures both standard unit tests and prerelease-deps unit tests pass cleanly without modifying autogenerated files or existing unit test assertions.
There was a problem hiding this comment.
Code Review
This pull request centralizes the disabling of AFE server timing for unit tests by moving the configuration from noxfile.py environment variables to tests/unit/conftest.py. The reviewer suggests using monkeypatch.setattr instead of manually setting and resetting _helpers.ENABLE_AFE_SERVER_TIMING to leverage pytest's built-in teardown mechanism and prevent state leakage.
| monkeypatch.setenv("SPANNER_DISABLE_AFE_SERVER_TIMING", "true") | ||
| _helpers.ENABLE_AFE_SERVER_TIMING = False | ||
| SpannerMetricsTracerFactory._metrics_tracer_factory = None | ||
| SpannerMetricsTracerFactory._current_metrics_tracer_ctx.set(None) | ||
| yield | ||
| # Reset singletons after test to ensure no leakage | ||
| _helpers.ENABLE_AFE_SERVER_TIMING = False | ||
| SpannerMetricsTracerFactory._metrics_tracer_factory = None | ||
| SpannerMetricsTracerFactory._current_metrics_tracer_ctx.set(None) |
There was a problem hiding this comment.
Instead of manually setting and resetting _helpers.ENABLE_AFE_SERVER_TIMING directly, use monkeypatch.setattr to leverage pytest's built-in teardown mechanism. This is more idiomatic and guarantees that the original state is restored automatically after each test, preventing potential state leakage.
| monkeypatch.setenv("SPANNER_DISABLE_AFE_SERVER_TIMING", "true") | |
| _helpers.ENABLE_AFE_SERVER_TIMING = False | |
| SpannerMetricsTracerFactory._metrics_tracer_factory = None | |
| SpannerMetricsTracerFactory._current_metrics_tracer_ctx.set(None) | |
| yield | |
| # Reset singletons after test to ensure no leakage | |
| _helpers.ENABLE_AFE_SERVER_TIMING = False | |
| SpannerMetricsTracerFactory._metrics_tracer_factory = None | |
| SpannerMetricsTracerFactory._current_metrics_tracer_ctx.set(None) | |
| monkeypatch.setenv("SPANNER_DISABLE_AFE_SERVER_TIMING", "true") | |
| monkeypatch.setattr(_helpers, "ENABLE_AFE_SERVER_TIMING", False) | |
| SpannerMetricsTracerFactory._metrics_tracer_factory = None | |
| SpannerMetricsTracerFactory._current_metrics_tracer_ctx.set(None) | |
| yield | |
| # Reset singletons after test to ensure no leakage | |
| SpannerMetricsTracerFactory._metrics_tracer_factory = None | |
| SpannerMetricsTracerFactory._current_metrics_tracer_ctx.set(None) |
…n conftest Addresses review comment on PR #17980 by using monkeypatch.setattr(_helpers, 'ENABLE_AFE_SERVER_TIMING', False) instead of direct mutation, allowing pytest to automatically restore state on teardown.
Reverts the edits to packages/google-cloud-spanner/noxfile.py from PR #17970 to restore compliance with owlbot/librarian autogeneration and fix issue #17974.
Disables AFE server timing in unit tests directly inside tests/unit/conftest.py by setting SPANNER_DISABLE_AFE_SERVER_TIMING="true" and _helpers.ENABLE_AFE_SERVER_TIMING = False. This ensures both standard unit tests and prerelease-deps unit tests pass cleanly without modifying autogenerated files or existing unit test assertions.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕