diff --git a/tests/conftest.py b/tests/conftest.py index a1b7bf2f..cf29b754 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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",