修复坏枪从来没有运行过的单元测试,为项目引入单元测试框架(终于。。)
This commit is contained in:
28
tests/conftest.py
Normal file
28
tests/conftest.py
Normal file
@ -0,0 +1,28 @@
|
||||
# 文件内容来源:
|
||||
# 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
|
||||
Reference in New Issue
Block a user