Skip to content

Commit 3be440a

Browse files
committed
refactor(tests): simplify pytest-asyncio configuration by removing custom event loop fixture and setting defaults in pytest_configure
fix(pyproject.toml): add asyncio_default_fixture_loop_scope to set default event loop scope for async tests
1 parent 97eb934 commit 3be440a

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ build-backend = "hatchling.build"
2828

2929
[tool.pytest.ini_options]
3030
asyncio_mode = "strict"
31-
testpaths = "tests"
31+
testpaths = "tests"
32+
# Set default event loop scope for async tests
33+
asyncio_default_fixture_loop_scope = "function"

tests/conftest.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import pytest
2-
import asyncio
32

4-
# Configure pytest-asyncio to use function scope
3+
# Configure pytest-asyncio
54
def pytest_configure(config):
6-
config.option.asyncio_mode = "strict"
7-
8-
@pytest.fixture(scope="function")
9-
def event_loop():
10-
"""Create a new event loop for each test case"""
11-
loop = asyncio.new_event_loop()
12-
yield loop
13-
loop.close()
5+
"""Configure pytest-asyncio defaults"""
6+
config.option.asyncio_mode = "strict"

0 commit comments

Comments
 (0)