mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
📝 Docs: 添加 pytest-asyncio 配置 (#3136)
This commit is contained in:
parent
980affd31b
commit
232b7134f0
@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
|
|||||||
```python title=tests/conftest.py
|
```python title=tests/conftest.py
|
||||||
import pytest
|
import pytest
|
||||||
import nonebot
|
import nonebot
|
||||||
|
from pytest_asyncio import is_async_test
|
||||||
# 导入适配器
|
# 导入适配器
|
||||||
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
||||||
|
|
||||||
|
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)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
async def after_nonebot_init(after_nonebot_init: None):
|
async def after_nonebot_init(after_nonebot_init: None):
|
||||||
# 加载适配器
|
# 加载适配器
|
||||||
|
@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
|
|||||||
```python title=tests/conftest.py
|
```python title=tests/conftest.py
|
||||||
import pytest
|
import pytest
|
||||||
import nonebot
|
import nonebot
|
||||||
|
from pytest_asyncio import is_async_test
|
||||||
# 导入适配器
|
# 导入适配器
|
||||||
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
||||||
|
|
||||||
|
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)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
async def after_nonebot_init(after_nonebot_init: None):
|
async def after_nonebot_init(after_nonebot_init: None):
|
||||||
# 加载适配器
|
# 加载适配器
|
||||||
|
@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
|
|||||||
```python title=tests/conftest.py
|
```python title=tests/conftest.py
|
||||||
import pytest
|
import pytest
|
||||||
import nonebot
|
import nonebot
|
||||||
|
from pytest_asyncio import is_async_test
|
||||||
# 导入适配器
|
# 导入适配器
|
||||||
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
||||||
|
|
||||||
|
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)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
async def after_nonebot_init(after_nonebot_init: None):
|
async def after_nonebot_init(after_nonebot_init: None):
|
||||||
# 加载适配器
|
# 加载适配器
|
||||||
|
@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
|
|||||||
```python title=tests/conftest.py
|
```python title=tests/conftest.py
|
||||||
import pytest
|
import pytest
|
||||||
import nonebot
|
import nonebot
|
||||||
|
from pytest_asyncio import is_async_test
|
||||||
# 导入适配器
|
# 导入适配器
|
||||||
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
||||||
|
|
||||||
|
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)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
async def after_nonebot_init(after_nonebot_init: None):
|
async def after_nonebot_init(after_nonebot_init: None):
|
||||||
# 加载适配器
|
# 加载适配器
|
||||||
|
@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
|
|||||||
```python title=tests/conftest.py
|
```python title=tests/conftest.py
|
||||||
import pytest
|
import pytest
|
||||||
import nonebot
|
import nonebot
|
||||||
|
from pytest_asyncio import is_async_test
|
||||||
# 导入适配器
|
# 导入适配器
|
||||||
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
from nonebot.adapters.console import Adapter as ConsoleAdapter
|
||||||
|
|
||||||
|
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)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
async def after_nonebot_init(after_nonebot_init: None):
|
async def after_nonebot_init(after_nonebot_init: None):
|
||||||
# 加载适配器
|
# 加载适配器
|
||||||
|
Loading…
Reference in New Issue
Block a user