Files
mcp-nextcloud/tests/unit/conftest.py
T
Chris CoutinhoandClaude Opus 4.7 79ea4e9e21 fix(config): emit background-ops advisory logs once per process
`_get_background_operations_enabled()` was emitting three advisory log
lines (1 INFO + 2 deprecation WARNINGs) on every call. Because
`get_settings()` is intentionally non-cached and runs on every MCP tool
invocation via `get_client()`, the "Automatically enabled background
operations for semantic search in multi-user mode" INFO line was
firing per-request — 569 entries/hour in one production tenant.

Gate the three log emissions behind a module-level
`_bg_ops_advisories_logged` flag, mirroring the existing
`_warn_missing_secret_once` precedent in
`vector/webhook_receiver.py`. The boolean-derivation path stays
unchanged, so the `Settings` value remains fresh per call.

Extends the autouse `_reload_dynaconf_after_test` fixture to reset the
new flag between tests, and adds two regression tests that call
`get_settings()` five times and assert each advisory fires exactly once.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 13:07:50 +02:00

23 lines
754 B
Python

"""Unit test configuration — shared fixtures for all unit tests."""
import pytest
@pytest.fixture(autouse=True)
def _reload_dynaconf_after_test():
"""Ensure dynaconf cache is clean between tests.
Dynaconf caches env var values at load time. Tests that modify os.environ
must call _reload_config() to refresh the cache. This fixture reloads
after each test to prevent leaked state.
Uses _dynaconf.reload() directly (without validate_all) since the
real env may have values that don't pass validators. Tests that need
validation should call _reload_config() explicitly.
"""
yield
from nextcloud_mcp_server import config as _config
_config._dynaconf.reload()
_config._bg_ops_advisories_logged = False