修复 PG 集成测试:连接池按测试新建(事件循环绑定)

This commit is contained in:
snowy-yang committed 2026-09-24 19:40:49 +08:00
1 parent d50e6ee20c
commit e9e5afa0da
1 file changed
+3 -1
+3 -1
View File
@@ -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()