From e9e5afa0da3deb5cb555b3f25e23a5187aff4f4a Mon Sep 17 00:00:00 2001 From: snowy-yang <102860110+snowy-yang@users.noreply.github.com> Date: Thu, 24 Sep 2026 19:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20PG=20=E9=9B=86=E6=88=90?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=9A=E8=BF=9E=E6=8E=A5=E6=B1=A0=E6=8C=89?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=B0=E5=BB=BA=EF=BC=88=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E7=BB=91=E5=AE=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_db_pg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_db_pg.py b/tests/test_db_pg.py index 264415a..5ae5f31 100644 --- a/tests/test_db_pg.py +++ b/tests/test_db_pg.py @@ -16,8 +16,10 @@ pytestmark = pytest.mark.skipif( reason="未配置 PG_DSN,跳过 PG 集成测试") -@pytest.fixture(scope="module") +@pytest.fixture async def conn(): + """每个测试独立的连接池:pytest-asyncio 默认每个测试一个新事件循环, + 连接池必须建在当前循环里,否则 asyncpg 会报 attached to a different loop""" await db.init(os.environ["PG_DSN"].strip()) yield await db.close()