mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
✅ Add pytest hook to tag async tests with session-scoped event loop.
This commit is contained in:
parent
d6b84a015f
commit
fd47a68865
@ -8,6 +8,7 @@ from nonebug import NONEBOT_INIT_KWARGS
|
||||
from nonebug.app import App
|
||||
from nonebug.mixin.process import MatcherContext
|
||||
import pytest
|
||||
from pytest_asyncio import is_async_test
|
||||
from pytest_mock import MockerFixture
|
||||
from respx import MockRouter
|
||||
|
||||
@ -22,6 +23,13 @@ def get_response_json(path: str) -> dict:
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(items: list[pytest.Item]):
|
||||
pytest_asyncio_tests = (item for item in items if is_async_test(item))
|
||||
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
|
||||
for async_test in pytest_asyncio_tests:
|
||||
async_test.add_marker(session_scope_marker, append=False)
|
||||
|
||||
|
||||
def pytest_configure(config: pytest.Config) -> None:
|
||||
config.stash[NONEBOT_INIT_KWARGS] = {
|
||||
"driver": "~fastapi+~httpx+~websockets",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user