From 781b1ce2aa5ccf0b128d6a33623a74720266bfbb Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Wed, 3 Jun 2026 18:34:45 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E5=8D=95=E6=B5=8B=20?= =?UTF-8?q?warnings=20=E5=B9=B6=E7=B2=BE=E7=A1=AE=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E4=B8=8A=E6=B8=B8=E5=BC=83=E7=94=A8=E5=91=8A=E8=AD=A6=20(#5889?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/indexer/parser/nexus_php.py | 2 +- pytest.ini | 11 +++++++++++ tests/test_agent_image_support.py | 5 +++-- tests/test_transfer_failed_retry_buttons.py | 7 ++++++- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 pytest.ini diff --git a/app/modules/indexer/parser/nexus_php.py b/app/modules/indexer/parser/nexus_php.py index a03558b4..3f39b07b 100644 --- a/app/modules/indexer/parser/nexus_php.py +++ b/app/modules/indexer/parser/nexus_php.py @@ -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) diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..811afe0a --- /dev/null +++ b/pytest.ini @@ -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 diff --git a/tests/test_agent_image_support.py b/tests/test_agent_image_support.py index 89163f1d..f972ee9e 100644 --- a/tests/test_agent_image_support.py +++ b/tests/test_agent_image_support.py @@ -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="帮我推荐一部电影", diff --git a/tests/test_transfer_failed_retry_buttons.py b/tests/test_transfer_failed_retry_buttons.py index ad8d37e3..de281f5a 100644 --- a/tests/test_transfer_failed_retry_buttons.py +++ b/tests/test_transfer_failed_retry_buttons.py @@ -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: