Skip to content

Commit 85ce9f6

Browse files
committed
Use Item.ihook instead of Config.hook
1 parent 72646b4 commit 85ce9f6

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pytest_asyncio/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def _collect_hook_loop_factories(
246246
config: Config,
247247
item: Item,
248248
) -> dict[str, LoopFactory] | None:
249-
hook_caller = config.hook.pytest_asyncio_loop_factories
249+
hook_caller = item.ihook.pytest_asyncio_loop_factories
250250
if not hook_caller.get_hookimpls():
251251
return None
252252

tests/test_loop_factory_parametrization.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,31 +323,27 @@ async def test_anything():
323323
)
324324

325325

326-
def test_nested_conftest_hook_implementations_respect_hook_order(
326+
def test_nested_conftest_hook_respects_conftest_locality(
327327
pytester: Pytester,
328328
) -> None:
329329
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
330330
pytester.makeconftest(dedent("""\
331331
import asyncio
332-
import pytest
333332
334333
class RootCustomEventLoop(asyncio.SelectorEventLoop):
335334
pass
336335
337-
@pytest.hookimpl(trylast=True)
338336
def pytest_asyncio_loop_factories(config, item):
339337
return {"root": RootCustomEventLoop}
340338
"""))
341-
subdir = pytester.mkdir("subtests")
339+
subdir = pytester.mkdir("subdir")
342340
subdir.joinpath("conftest.py").write_text(
343341
dedent("""\
344342
import asyncio
345-
import pytest
346343
347344
class SubCustomEventLoop(asyncio.SelectorEventLoop):
348345
pass
349346
350-
@pytest.hookimpl(tryfirst=True)
351347
def pytest_asyncio_loop_factories(config, item):
352348
return {"sub": SubCustomEventLoop}
353349
"""),
@@ -360,8 +356,10 @@ def pytest_asyncio_loop_factories(config, item):
360356
pytest_plugins = "pytest_asyncio"
361357
362358
@pytest.mark.asyncio
363-
async def test_uses_sub_loop():
364-
assert type(asyncio.get_running_loop()).__name__ == "SubCustomEventLoop"
359+
async def test_root_uses_root_loop():
360+
assert (
361+
type(asyncio.get_running_loop()).__name__ == "RootCustomEventLoop"
362+
)
365363
"""),
366364
)
367365
subdir.joinpath("test_sub.py").write_text(
@@ -372,7 +370,7 @@ async def test_uses_sub_loop():
372370
pytest_plugins = "pytest_asyncio"
373371
374372
@pytest.mark.asyncio
375-
async def test_uses_sub_loop():
373+
async def test_sub_uses_sub_loop():
376374
assert type(asyncio.get_running_loop()).__name__ == "SubCustomEventLoop"
377375
"""),
378376
)

0 commit comments

Comments
 (0)