@@ -18,6 +18,59 @@ which uses the twisted framework. test functions can return Deferred
1818objects and pytest will wait for their completion with this plugin.
1919
2020
21+ NOTICE: Python 3.8 with asyncio support
22+ =======================================
23+
24+ In Python 3.8, asyncio changed the default loop implementation to use
25+ their proactor. The proactor does not implement some methods used by
26+ Twisted's asyncio support. The result is a ``NotImplementedError ``
27+ exception such as below.
28+
29+ .. code-block :: pytb
30+
31+ <snip>
32+ File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\asyncioreactor.py", line 320, in install
33+ reactor = AsyncioSelectorReactor(eventloop)
34+ File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\asyncioreactor.py", line 69, in __init__
35+ super().__init__()
36+ File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\base.py", line 571, in __init__
37+ self.installWaker()
38+ File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
39+ self.addReader(self.waker)
40+ File "c:\projects\pytest-twisted\.tox\py38-asyncioreactor\lib\site-packages\twisted\internet\asyncioreactor.py", line 151, in addReader
41+ self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
42+ File "C:\Python38-x64\Lib\asyncio\events.py", line 501, in add_reader
43+ raise NotImplementedError
44+ NotImplementedError
45+
46+ The previous default, the selector loop, still works but you have to
47+ explicitly set it and do so early. The following ``conftest.py `` is provided
48+ for reference.
49+
50+ .. code-block :: python3
51+
52+ import sys
53+
54+ import pytest
55+ import pytest_twisted
56+
57+
58+ @pytest.hookimpl(tryfirst=True)
59+ def pytest_configure(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)
72+
73+
2174 Python 2 support plans
2275======================
2376
0 commit comments