Skip to content

Commit 41ba6e2

Browse files
committed
Make the proactor helper _private for now
1 parent 0bdf552 commit 41ba6e2

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

README.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,31 @@ exception such as below.
4444
NotImplementedError
4545
4646
The previous default, the selector loop, still works but you have to
47-
explicitly set it. ``pytest_twisted.use_asyncio_selector_if_required()``
48-
is provided to help in choosing the selector loop. It must be called
49-
early so the following `conftest.py` is suggested.
47+
explicitly set it and do so early. The following ``conftest.py`` is provided
48+
for reference.
5049

5150
.. code-block:: python3
5251
52+
import sys
53+
5354
import pytest
5455
import pytest_twisted
5556
5657
5758
@pytest.hookimpl(tryfirst=True)
5859
def pytest_configure(config):
59-
pytest_twisted.use_asyncio_selector_if_required(config=config)
60+
# https://twistedmatrix.com/trac/ticket/9766
61+
# https://github.com/pytest-dev/pytest-twisted/issues/80
62+
63+
if (
64+
config.getoption("reactor", "default") == "asyncio"
65+
and sys.platform == 'win32'
66+
and sys.version_info >= (3, 8)
67+
):
68+
import asyncio
69+
70+
selector_policy = asyncio.WindowsSelectorEventLoopPolicy()
71+
asyncio.set_event_loop_policy(selector_policy)
6072
6173
6274
Python 2 support plans

pytest_twisted.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ def pytest_configure(config):
329329
reactor_installers[config.getoption("reactor")]()
330330

331331

332-
def use_asyncio_selector_if_required(config):
332+
def _use_asyncio_selector_if_required(config):
333333
# https://twistedmatrix.com/trac/ticket/9766
334+
# https://github.com/pytest-dev/pytest-twisted/issues/80
334335

335336
if (
336337
config.getoption("reactor", "default") == "asyncio"

testing/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
@pytest.hookimpl(tryfirst=True)
99
def pytest_configure(config):
10-
pytest_twisted.use_asyncio_selector_if_required(config=config)
10+
pytest_twisted._use_asyncio_selector_if_required(config=config)

testing/test_basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _default_conftest(testdir):
5858
5959
@pytest.hookimpl(tryfirst=True)
6060
def pytest_configure(config):
61-
pytest_twisted.use_asyncio_selector_if_required(config=config)
61+
pytest_twisted._use_asyncio_selector_if_required(config=config)
6262
"""))
6363

6464

@@ -646,7 +646,7 @@ def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
646646
647647
@pytest.hookimpl(tryfirst=True)
648648
def pytest_configure(config):
649-
pt.use_asyncio_selector_if_required(config=config)
649+
pt._use_asyncio_selector_if_required(config=config)
650650
651651
pt.init_asyncio_reactor()
652652
d = defer.Deferred()
@@ -679,7 +679,7 @@ def test_wrong_reactor_with_asyncio(testdir, cmd_opts, request):
679679
680680
@pytest.hookimpl(tryfirst=True)
681681
def pytest_configure(config):
682-
pytest_twisted.use_asyncio_selector_if_required(config=config)
682+
pytest_twisted._use_asyncio_selector_if_required(config=config)
683683
684684
def pytest_addhooks():
685685
import twisted.internet.default

0 commit comments

Comments
 (0)