test: 修复单测 warnings 并精确忽略上游弃用告警 (#5889)

This commit is contained in:
InfinityPacer
2026-06-03 18:34:45 +08:00
committed by GitHub
parent 791f1fe4ac
commit 781b1ce2aa
4 changed files with 21 additions and 4 deletions

View File

@@ -116,7 +116,7 @@ class NexusPhpSiteUserInfo(SiteParserBase):
has_ucoin, self.bonus = self._parse_ucoin(html)
if has_ucoin:
return
tmps = html.xpath('//a[contains(@href,"mybonus")]/text()') if html else None
tmps = html.xpath('//a[contains(@href,"mybonus")]/text()') if html is not None else None
if tmps:
bonus_text = str(tmps[0]).strip()
bonus_match = re.search(r"([\d,.]+)", bonus_text)

11
pytest.ini Normal file
View File

@@ -0,0 +1,11 @@
[pytest]
# 仅对「无法在本仓修复根因」的已知上游/三方弃用告警做精确忽略,保持测试输出干净、
# 让本仓自身的新告警更醒目。本仓代码引发的告警一律不在此忽略,应在源码/用例处修复。
filterwarnings =
ignore:datetime.datetime.utcfromtimestamp\(\) is deprecated:DeprecationWarning
ignore:websockets.legacy is deprecated:DeprecationWarning
ignore:websockets.InvalidStatusCode is deprecated:DeprecationWarning
ignore:pkg_resources is deprecated as an API:DeprecationWarning
ignore:Deprecated call to .pkg_resources.declare_namespace:DeprecationWarning
ignore:'crypt' is deprecated:DeprecationWarning
ignore:'audioop' is deprecated:DeprecationWarning

View File

@@ -453,7 +453,8 @@ class AgentImageSupportTest(unittest.TestCase):
) as prepare_files, patch(
"app.chain.message.agent_manager.process_message", new_callable=AsyncMock
) as process_message, patch(
"app.chain.message.asyncio.run_coroutine_threadsafe"
"app.chain.message.asyncio.run_coroutine_threadsafe",
side_effect=lambda coro, _loop: coro.close(),
) as run_coroutine_threadsafe:
chain._handle_ai_message(
text="/ai 帮我看看这张图",
@@ -486,7 +487,7 @@ class AgentImageSupportTest(unittest.TestCase):
"app.chain.message.agent_manager.process_message", new_callable=AsyncMock
) as process_message, patch(
"app.chain.message.asyncio.run_coroutine_threadsafe",
side_effect=lambda coro, _loop: (coro.close(), Mock())[1],
side_effect=lambda coro, _loop: coro.close(),
):
chain._handle_ai_message(
text="帮我推荐一部电影",

View File

@@ -95,11 +95,16 @@ class TestTransferFailedRetryButtons(unittest.TestCase):
errmsg="未识别到媒体信息",
)
def _close_pending_coro(coro, *args, **kwargs):
"""关闭被调度的协程:测试中事件循环未运行,不关闭会残留 never-awaited 警告。"""
coro.close()
with patch.object(settings, "AI_AGENT_ENABLE", True):
with patch(
"app.chain.message.TransferHistoryOper"
) as history_oper_cls, patch(
"app.chain.message.asyncio.run_coroutine_threadsafe"
"app.chain.message.asyncio.run_coroutine_threadsafe",
side_effect=_close_pending_coro,
) as run_task:
history_oper_cls.return_value.get.return_value = history
with patch.object(chain, "post_message") as post_message: