Skip to content
Draft
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
18 changes: 9 additions & 9 deletions tests/dragonfly/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,6 @@ def parse_args(args: List[str]) -> Dict[str, Union[str, None]]:
return args_dict


@pytest_asyncio.fixture(scope="class")
def event_loop():
loop = asyncio.new_event_loop()
yield loop
loop.close()


@pytest_asyncio.fixture(scope="class", params=[{}])
async def df_factory(
request,
Expand Down Expand Up @@ -363,15 +356,22 @@ async def async_pool(df_server: DflyInstance):


@pytest_asyncio.fixture(scope="function")
async def async_client(async_pool):
async def async_client(df_server: DflyInstance):
"""
Return an async client to the default instance with all entries flushed.
"""
client = aioredis.Redis(connection_pool=async_pool)
client = aioredis.Redis(
host="localhost",
port=df_server.port,
db=DATABASE_INDEX,
decode_responses=True,
max_connections=32,
)
await client.client_setname("default-async-fixture")
await client.flushall()
await client.select(DATABASE_INDEX)
yield client
await client.aclose()


def pytest_addoption(parser):
Expand Down
4 changes: 2 additions & 2 deletions tests/dragonfly/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ packaging>=23.1
pluggy>=1.0.0
py>=1.11.0
pyparsing>=3.0.9
pytest>=7.1.2
pytest>=8.3,<9.0
redis>=5.2.1
tomli>=2.0.1
wrapt>=1.14.1
pytest-asyncio==0.20.1
pytest-asyncio>=0.24.0,<0.25.0
Comment thread
glevkovich marked this conversation as resolved.
pytest-repeat>=0.9.3
pymemcache>=4.0.0
meta_memcache>=2
Expand Down
6 changes: 4 additions & 2 deletions tests/dragonfly/snapshot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ async def test_exit_on_s3_snapshot_load_err(df_factory):
reason="AWS S3 snapshots bucket or credentials are not configured",
)
@dfly_args({**BASIC_ARGS})
async def test_s3_snapshot(async_client, tmp_dir):
async def test_s3_snapshot(df_server, tmp_dir):
async_client = df_server.client()
seeder = DebugPopulateSeeder(key_target=10_000)
await seeder.run(async_client)

Expand Down Expand Up @@ -460,7 +461,8 @@ async def test_s3_reload_snapshot_after_restart(df_factory, tmp_dir):
reason="AWS S3 snapshots bucket or credentials are not configured",
)
@dfly_args({**BASIC_ARGS})
async def test_s3_save_local_dir(async_client, tmp_dir):
async def test_s3_save_local_dir(df_server, tmp_dir):
async_client = df_server.client()
seeder = DebugPopulateSeeder(key_target=10_000)
await seeder.run(async_client)

Expand Down
1 change: 1 addition & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ log_date_format = %Y-%m-%d %H:%M:%S
log_file_level=INFO
log_cli = true
asyncio_mode=auto
asyncio_default_fixture_loop_scope=session
Comment thread
glevkovich marked this conversation as resolved.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a mistake.
It should be:

asyncio_default_fixture_loop_scope=class

or even

asyncio_default_fixture_loop_scope=function

Copy link
Copy Markdown
Contributor Author

@glevkovich glevkovich Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a mistake - tried both and they crash:

  • function: crash with "Future attached to a different loop" because df_factory in tests/dragonfly/conftest.py is class-scoped and outlives the per-function loop.

  • class: crash with with "UsageError: test_client_migrate is marked to be run in an event loop with scope class, but is not part of any class" - many tests are standalone functions, not inside a class.

session is the only scope that works for me, with both class-scoped fixtures and module-level test functions under pytest-asyncio 0.24's scoping rules.

addopts = -ra --emoji --showlocals -m "not large"
markers =
# Tests that should only run on release builds and take significant amount of time to run.
Expand Down
Loading