小编She*_*ver的帖子

Pytest asyncio事件绑定到不同的事件循环,事件循环关闭

我正在尝试为我的 fastapi 应用程序编写一些测试

\n
\n

我正在使用prisma-client-py数据库。我不知道这是否会改变什么

\n
\n

一切都按预期工作,除了第一个和最后一个之外,它们都因相同的错误而失败:

\n
RuntimeError: <asyncio.locks.Event object at 0x7f5696832950 [unset]> is bound to a different event loop\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的conftest.py

\n
import os\nimport asyncio\nimport pytest\nfrom typing import Any, AsyncGenerator, Generator, Iterator\n\nfrom fastapi import FastAPI\nfrom fastapi.testclient import TestClient\nfrom prisma import Prisma, register\n\n\nfrom server.database.base import *\nfrom server.config.exceptions import configure_exception_handlers\nfrom server.config.settings import settings\nfrom server.apis import apis\n\n\ndef start_application() -> FastAPI:\n    """\n    Return a FastAPI app\n    """\n    _app = FastAPI(\n        title=str(settings.TITLE),\n        description=str(settings.DESCRIPTION),\n        version=str(settings.VERSION),\n    )\n    configure_exception_handlers(_app)\n    _app.include_router(apis)\n    return …
Run Code Online (Sandbox Code Playgroud)

python pytest prisma pytest-asyncio fastapi

15
推荐指数
1
解决办法
2799
查看次数

标签 统计

fastapi ×1

prisma ×1

pytest ×1

pytest-asyncio ×1

python ×1