Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: 添加 pytest-asyncio 配置 #3136

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions website/docs/best-practice/testing/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
```python title=tests/conftest.py
import pytest
import nonebot
from pytest_asyncio import is_async_test
# 导入适配器
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)
async def after_nonebot_init(after_nonebot_init: None):
# 加载适配器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
```python title=tests/conftest.py
import pytest
import nonebot
from pytest_asyncio import is_async_test
# 导入适配器
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)
async def after_nonebot_init(after_nonebot_init: None):
# 加载适配器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
```python title=tests/conftest.py
import pytest
import nonebot
from pytest_asyncio import is_async_test
# 导入适配器
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)
async def after_nonebot_init(after_nonebot_init: None):
# 加载适配器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
```python title=tests/conftest.py
import pytest
import nonebot
from pytest_asyncio import is_async_test
# 导入适配器
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)
async def after_nonebot_init(after_nonebot_init: None):
# 加载适配器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
```python title=tests/conftest.py
import pytest
import nonebot
from pytest_asyncio import is_async_test
# 导入适配器
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)
async def after_nonebot_init(after_nonebot_init: None):
# 加载适配器
Expand Down