mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
fix(tests): make pytest suite runnable from a fresh checkout (CI fix)
PR#2 CI: the Python job failed with 17 FileNotFoundError collection errors. Widening CI from upstream's smoke-test-only to the full suite exposed that the suite depends on main/xiaozhi-server/data/.config.yaml, which is gitignored and therefore absent on CI runners (dev boxes always have it, so the local rebase gate never caught it). - add tracked tests/testdata/test-config.yaml (placeholder keys, empty manager-api block, same shape as the local stub) - conftest falls back to it when data/.config.yaml is missing (explicit PYTEST_CONFIG_FILE still wins) - neutralize config.settings/config.logger check_config_file bindings and logger's load_config so setup_logging() at module import works without a real deployment config; these names are bound at import time via manage_api_client -> config.logger, so patching the source modules alone was not enough Verified on a clean clone with py3.10 + full requirements: 58 passed, 5 skipped; lifecycle unittests 11 OK on both clean clone and dev box.
This commit is contained in:
parent
6f4728085b
commit
d51c54f483
2 changed files with 62 additions and 3 deletions
|
|
@ -66,9 +66,19 @@ except Exception:
|
||||||
# 1. File pointed to by environment variable ``PYTEST_CONFIG_FILE`` (recommended - isolated test config)
|
# 1. File pointed to by environment variable ``PYTEST_CONFIG_FILE`` (recommended - isolated test config)
|
||||||
# 2. data/.config.yaml (Production / Single-module deployment config)
|
# 2. data/.config.yaml (Production / Single-module deployment config)
|
||||||
_DEFAULT_CUSTOM = _PROJECT_ROOT / "data" / ".config.yaml"
|
_DEFAULT_CUSTOM = _PROJECT_ROOT / "data" / ".config.yaml"
|
||||||
_CUSTOM_CONFIG = Path(os.environ["PYTEST_CONFIG_FILE"]) if os.environ.get(
|
|
||||||
"PYTEST_CONFIG_FILE"
|
# Fresh checkout / CI fallback: the real data/.config.yaml is gitignored, so
|
||||||
) else _DEFAULT_CUSTOM
|
# without this the suite only passes on dev boxes that happen to have one.
|
||||||
|
# Fall back to the tracked test-only config (placeholder keys, empty
|
||||||
|
# manager-api block) so a clean clone runs the exact same provider tests.
|
||||||
|
_TESTDATA_CONFIG = Path(__file__).resolve().parent / "testdata" / "test-config.yaml"
|
||||||
|
if os.environ.get("PYTEST_CONFIG_FILE"):
|
||||||
|
# Explicit override always wins, even if the path does not exist yet.
|
||||||
|
_CUSTOM_CONFIG = Path(os.environ["PYTEST_CONFIG_FILE"])
|
||||||
|
elif _DEFAULT_CUSTOM.exists():
|
||||||
|
_CUSTOM_CONFIG = _DEFAULT_CUSTOM
|
||||||
|
else:
|
||||||
|
_CUSTOM_CONFIG = _TESTDATA_CONFIG
|
||||||
|
|
||||||
|
|
||||||
def _load_via_file_merge() -> dict:
|
def _load_via_file_merge() -> dict:
|
||||||
|
|
@ -141,7 +151,17 @@ def _init_service_noop(_config):
|
||||||
|
|
||||||
import config.config_loader as _cl # noqa: E402
|
import config.config_loader as _cl # noqa: E402
|
||||||
import config.manage_api_client as _mac # noqa: E402
|
import config.manage_api_client as _mac # noqa: E402
|
||||||
|
import config.settings as _settings # noqa: E402
|
||||||
|
import config.logger as _logger_mod # noqa: E402
|
||||||
|
|
||||||
_cl.load_config = _load_config_patched
|
_cl.load_config = _load_config_patched
|
||||||
|
# data/.config.yaml is gitignored, so a fresh checkout (CI) has none: skip the
|
||||||
|
# deployment-file check and keep log config coming from the merged CONFIG above.
|
||||||
|
# config.logger binds these names at import time (via manage_api_client), so
|
||||||
|
# patch the already-imported references as well, not just the source modules.
|
||||||
|
_settings.check_config_file = lambda: None
|
||||||
|
_logger_mod.check_config_file = lambda: None
|
||||||
|
_logger_mod.load_config = _load_config_patched
|
||||||
_mac.init_service = _init_service_noop
|
_mac.init_service = _init_service_noop
|
||||||
_mac.get_server_config = _get_server_config_patched
|
_mac.get_server_config = _get_server_config_patched
|
||||||
# Clear ManageApiClient singleton to avoid prior instantiation triggered by other code.
|
# Clear ManageApiClient singleton to avoid prior instantiation triggered by other code.
|
||||||
|
|
|
||||||
39
main/xiaozhi-server/tests/testdata/test-config.yaml
vendored
Normal file
39
main/xiaozhi-server/tests/testdata/test-config.yaml
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Test-only deployment config, tracked in git and used by tests/conftest.py as
|
||||||
|
# a fallback when the real (gitignored) data/.config.yaml is absent — e.g. in
|
||||||
|
# CI or a fresh checkout. Minimal single-module stub so provider tests can
|
||||||
|
# construct objects against the mock shims in conftest. Placeholder keys only;
|
||||||
|
# never point it at a real manager-api.
|
||||||
|
manager-api:
|
||||||
|
url: ""
|
||||||
|
secret: ""
|
||||||
|
|
||||||
|
selected_module:
|
||||||
|
VAD: SileroVAD
|
||||||
|
ASR: OpenaiASR
|
||||||
|
LLM: OpenAILLM
|
||||||
|
TTS: EdgeTTS
|
||||||
|
Memory: nomem
|
||||||
|
Intent: nointent
|
||||||
|
|
||||||
|
ASR:
|
||||||
|
OpenaiASR:
|
||||||
|
type: openai
|
||||||
|
model_name: whisper-1
|
||||||
|
api_key: placeholder-key-do-not-use
|
||||||
|
base_url: http://127.0.0.1:18000/v1
|
||||||
|
|
||||||
|
LLM:
|
||||||
|
OpenAILLM:
|
||||||
|
type: openai
|
||||||
|
model_name: gpt-4o-mini
|
||||||
|
api_key: placeholder-key-do-not-use
|
||||||
|
base_url: http://127.0.0.1:18000/v1
|
||||||
|
|
||||||
|
TTS:
|
||||||
|
EdgeTTS:
|
||||||
|
type: edge
|
||||||
|
voice_name: en-US-AriaNeural
|
||||||
|
|
||||||
|
Memory:
|
||||||
|
nomem:
|
||||||
|
type: nomem
|
||||||
Loading…
Reference in a new issue