@@ -49,6 +49,19 @@ def format_run_result_output_for_assert(run_result):
4949 )
5050
5151
52+ @pytest .fixture (name = "default_conftest" , autouse = True )
53+ def _default_conftest (testdir ):
54+ testdir .makeconftest (textwrap .dedent ("""
55+ import pytest
56+ import pytest_twisted
57+
58+
59+ @pytest.hookimpl(tryfirst=True)
60+ def pytest_configure(config):
61+ pytest_twisted._use_asyncio_selector_if_required(config=config)
62+ """ ))
63+
64+
5265def skip_if_reactor_not (request , expected_reactor ):
5366 actual_reactor = request .config .getoption ("reactor" , "default" )
5467 if actual_reactor != expected_reactor :
@@ -334,7 +347,10 @@ def test_async_fixture(testdir, cmd_opts):
334347 import pytest
335348 import pytest_twisted
336349
337- @pytest_twisted.async_fixture(scope="function", params=["fs", "imap", "web"])
350+ @pytest_twisted.async_fixture(
351+ scope="function",
352+ params=["fs", "imap", "web"],
353+ )
338354 @pytest.mark.redgreenblue
339355 async def foo(request):
340356 d1, d2 = defer.Deferred(), defer.Deferred()
@@ -627,10 +643,14 @@ def main():
627643def test_blockon_in_hook_with_asyncio (testdir , cmd_opts , request ):
628644 skip_if_reactor_not (request , "asyncio" )
629645 conftest_file = """
646+ import pytest
630647 import pytest_twisted as pt
631648 from twisted.internet import defer
632649
650+ @pytest.hookimpl(tryfirst=True)
633651 def pytest_configure(config):
652+ pt._use_asyncio_selector_if_required(config=config)
653+
634654 pt.init_asyncio_reactor()
635655 d = defer.Deferred()
636656
@@ -656,6 +676,14 @@ def test_succeed():
656676def test_wrong_reactor_with_asyncio (testdir , cmd_opts , request ):
657677 skip_if_reactor_not (request , "asyncio" )
658678 conftest_file = """
679+ import pytest
680+ import pytest_twisted
681+
682+
683+ @pytest.hookimpl(tryfirst=True)
684+ def pytest_configure(config):
685+ pytest_twisted._use_asyncio_selector_if_required(config=config)
686+
659687 def pytest_addhooks():
660688 import twisted.internet.default
661689 twisted.internet.default.install()
0 commit comments