mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
要真凭据的用例打标记统一剔除
Edge TTS 那条要连微软公网,runner 的出口 IP 会被风控挡掉。以前在 CI 命令行上用 -k 排除,看不出排掉了什么。现在给它打 live_api 标记,由 conftest 统一剔除,日志里列出剔的是哪几条。
This commit is contained in:
parent
e3e043a9ed
commit
aff47ee6de
4 changed files with 40 additions and 6 deletions
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
|
|
@ -42,9 +42,9 @@ jobs:
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
working-directory: main/xiaozhi-server
|
working-directory: main/xiaozhi-server
|
||||||
run: |
|
run: |
|
||||||
# Edge TTS 那条要连微软公网,runner 的出口 IP 会被风控挡掉,先排除。
|
# 要真凭据/真网络的用例由 tests/conftest.py 按 live_api 标记统一剔除,
|
||||||
# 根治办法是给它打 live 标记,让 mock 模式下自动不收(另开一条改)
|
# 剔掉的是哪几条会打在日志里
|
||||||
pytest tests/ -v -k "not test_tts_text_to_speak_writes_file"
|
pytest tests/ -v
|
||||||
|
|
||||||
java:
|
java:
|
||||||
name: Java (manager-api)
|
name: Java (manager-api)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ python_files = ["test_*.py"]
|
||||||
python_classes = ["Test*"]
|
python_classes = ["Test*"]
|
||||||
python_functions = ["test_*"]
|
python_functions = ["test_*"]
|
||||||
addopts = "-ra"
|
addopts = "-ra"
|
||||||
|
markers = [
|
||||||
|
"live_api: 需要真凭据或真网络的用例,mock 模式下由 conftest 剔除并列出",
|
||||||
|
]
|
||||||
filterwarnings = [
|
filterwarnings = [
|
||||||
"ignore::DeprecationWarning",
|
"ignore::DeprecationWarning",
|
||||||
]
|
]
|
||||||
|
|
@ -454,8 +454,35 @@ import pytest # noqa: E402 (after conftest hooks so pytest is initialised)
|
||||||
|
|
||||||
|
|
||||||
def pytest_collection_modifyitems(config, items):
|
def pytest_collection_modifyitems(config, items):
|
||||||
"""Live 模式下:``live_api`` 标记的测试必须配齐密钥才能跑(否则 skip)。"""
|
"""Mock 模式下:``live_api`` 标记的用例要真凭据或真网络,不收,并列出是哪几条。
|
||||||
|
|
||||||
|
以前是在 CI 命令行上用 ``-k`` 排除,看不出排掉了什么、为什么排。
|
||||||
|
改成打标记 + 这里统一剔除,日志里会一条条列出来,剔了什么一目了然。
|
||||||
|
"""
|
||||||
if LIVE_API_TESTS:
|
if LIVE_API_TESTS:
|
||||||
return
|
return
|
||||||
# Mock 模式下不强行 skip:测试应该都能跑(用 shim)。
|
|
||||||
return
|
keep = []
|
||||||
|
drop = []
|
||||||
|
for item in items:
|
||||||
|
if "live_api" in item.keywords:
|
||||||
|
drop.append(item)
|
||||||
|
else:
|
||||||
|
keep.append(item)
|
||||||
|
|
||||||
|
if not drop:
|
||||||
|
return
|
||||||
|
|
||||||
|
print(
|
||||||
|
"\n[conftest] 下面这些用例要真凭据或真网络,mock 模式下不收:",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
for item in drop:
|
||||||
|
print(f"[conftest] - {item.nodeid}", flush=True)
|
||||||
|
print(
|
||||||
|
"[conftest] 真请求模式:export RUN_LIVE_API_TESTS=1 并配好凭据后再跑。\n",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
config.hook.pytest_deselected(items=drop)
|
||||||
|
items[:] = keep
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,13 @@ def test_tts_provider_has_output_dir() -> None:
|
||||||
assert provider.output_file, "output_file 不应为空"
|
assert provider.output_file, "output_file 不应为空"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.live_api
|
||||||
def test_tts_text_to_speak_writes_file() -> None:
|
def test_tts_text_to_speak_writes_file() -> None:
|
||||||
"""Mock 模式:断言 file 存在即可。Live 模式:断言 size > 0。
|
"""Mock 模式:断言 file 存在即可。Live 模式:断言 size > 0。
|
||||||
|
|
||||||
|
这条要连微软公网,runner 的出口 IP 会被风控挡掉,所以打了 live_api 标记:
|
||||||
|
mock 模式下由 conftest 统一剔除(会列出剔的是哪几条),live 模式下才收。
|
||||||
|
|
||||||
参考 performance_tester_tts.py 的实现:
|
参考 performance_tester_tts.py 的实现:
|
||||||
- mock conn(sample_rate/audio_format/stop_event/client_abort/headers)
|
- mock conn(sample_rate/audio_format/stop_event/client_abort/headers)
|
||||||
和 opus_encoder(SimpleNamespace 占位即可)
|
和 opus_encoder(SimpleNamespace 占位即可)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue