File tree Expand file tree Collapse file tree 5 files changed +35
-0
lines changed
docs/best-practice/testing
version-2.3.1/best-practice/testing
version-2.3.2/best-practice/testing
version-2.3.3/best-practice/testing
version-2.4.0/best-practice/testing Expand file tree Collapse file tree 5 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
8989``` python title=tests/conftest.py
9090import pytest
9191import nonebot
92+ from pytest_asyncio import is_async_test
9293# 导入适配器
9394from nonebot.adapters.console import Adapter as ConsoleAdapter
9495
96+ def pytest_collection_modifyitems (items : list[pytest.Item]):
97+ pytest_asyncio_tests = (item for item in items if is_async_test(item))
98+ session_scope_marker = pytest.mark.asyncio(loop_scope = " session" )
99+ for async_test in pytest_asyncio_tests:
100+ async_test.add_marker(session_scope_marker, append = False )
101+
95102@pytest.fixture (scope = " session" , autouse = True )
96103async def after_nonebot_init (after_nonebot_init : None ):
97104 # 加载适配器
Original file line number Diff line number Diff line change @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
8989``` python title=tests/conftest.py
9090import pytest
9191import nonebot
92+ from pytest_asyncio import is_async_test
9293# 导入适配器
9394from nonebot.adapters.console import Adapter as ConsoleAdapter
9495
96+ def pytest_collection_modifyitems (items : list[pytest.Item]):
97+ pytest_asyncio_tests = (item for item in items if is_async_test(item))
98+ session_scope_marker = pytest.mark.asyncio(loop_scope = " session" )
99+ for async_test in pytest_asyncio_tests:
100+ async_test.add_marker(session_scope_marker, append = False )
101+
95102@pytest.fixture (scope = " session" , autouse = True )
96103async def after_nonebot_init (after_nonebot_init : None ):
97104 # 加载适配器
Original file line number Diff line number Diff line change @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
8989``` python title=tests/conftest.py
9090import pytest
9191import nonebot
92+ from pytest_asyncio import is_async_test
9293# 导入适配器
9394from nonebot.adapters.console import Adapter as ConsoleAdapter
9495
96+ def pytest_collection_modifyitems (items : list[pytest.Item]):
97+ pytest_asyncio_tests = (item for item in items if is_async_test(item))
98+ session_scope_marker = pytest.mark.asyncio(loop_scope = " session" )
99+ for async_test in pytest_asyncio_tests:
100+ async_test.add_marker(session_scope_marker, append = False )
101+
95102@pytest.fixture (scope = " session" , autouse = True )
96103async def after_nonebot_init (after_nonebot_init : None ):
97104 # 加载适配器
Original file line number Diff line number Diff line change @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
8989``` python title=tests/conftest.py
9090import pytest
9191import nonebot
92+ from pytest_asyncio import is_async_test
9293# 导入适配器
9394from nonebot.adapters.console import Adapter as ConsoleAdapter
9495
96+ def pytest_collection_modifyitems (items : list[pytest.Item]):
97+ pytest_asyncio_tests = (item for item in items if is_async_test(item))
98+ session_scope_marker = pytest.mark.asyncio(loop_scope = " session" )
99+ for async_test in pytest_asyncio_tests:
100+ async_test.add_marker(session_scope_marker, append = False )
101+
95102@pytest.fixture (scope = " session" , autouse = True )
96103async def after_nonebot_init (after_nonebot_init : None ):
97104 # 加载适配器
Original file line number Diff line number Diff line change @@ -89,9 +89,16 @@ asyncio_default_fixture_loop_scope = "session"
8989``` python title=tests/conftest.py
9090import pytest
9191import nonebot
92+ from pytest_asyncio import is_async_test
9293# 导入适配器
9394from nonebot.adapters.console import Adapter as ConsoleAdapter
9495
96+ def pytest_collection_modifyitems (items : list[pytest.Item]):
97+ pytest_asyncio_tests = (item for item in items if is_async_test(item))
98+ session_scope_marker = pytest.mark.asyncio(loop_scope = " session" )
99+ for async_test in pytest_asyncio_tests:
100+ async_test.add_marker(session_scope_marker, append = False )
101+
95102@pytest.fixture (scope = " session" , autouse = True )
96103async def after_nonebot_init (after_nonebot_init : None ):
97104 # 加载适配器
You can’t perform that action at this time.
0 commit comments