forked from mttu-developers/konabot
29 lines
939 B
Python
29 lines
939 B
Python
# 文件内容来源:
|
|
# https://nonebot.dev/docs/best-practice/testing/
|
|
# 保证 nonebug 测试框架正常运作
|
|
|
|
import pytest
|
|
import nonebot
|
|
from pytest_asyncio import is_async_test
|
|
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
|
from nonebug import NONEBOT_START_LIFESPAN
|
|
|
|
|
|
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)
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
async def after_nonebot_init(after_nonebot_init: None):
|
|
driver = nonebot.get_driver()
|
|
driver.register_adapter(ConsoleAdapter)
|
|
|
|
nonebot.load_from_toml("pyproject.toml")
|
|
|
|
|
|
def pytest_configure(config: pytest.Config):
|
|
config.stash[NONEBOT_START_LIFESPAN] = False
|