Skip to content

Commit d869a7c

Browse files
authored
Merge pull request #75 from pytest-dev/py38
Update testing etc for Python 3.8
2 parents d7b2275 + 44130c8 commit d869a7c

File tree

9 files changed

+118
-2
lines changed

9 files changed

+118
-2
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: CPython 3.7
3838
tox: py37
3939
action: 3.7
40+
- name: CPython 3.8
41+
tox: py38
42+
action: 3.8
4043
reactor:
4144
- name: default
4245
tox: default

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ matrix:
88
- python: 3.7
99
dist: xenial
1010
sudo: true
11+
- python: 3.8
12+
dist: xenial
13+
sudo: true
1114

1215
addons:
1316
apt:

README.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,59 @@ which uses the twisted framework. test functions can return Deferred
1818
objects 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

appveyor.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ environment:
2626
- TOXENV: py37-defaultreactor, win-py37-qt5reactor, py37-asyncioreactor
2727
PYTHON: "C:\\Python37-x64"
2828

29+
- TOXENV: py38-defaultreactor, win-py38-qt5reactor, py38-asyncioreactor
30+
PYTHON: "C:\\Python38"
31+
32+
- TOXENV: py38-defaultreactor, win-py38-qt5reactor, py38-asyncioreactor
33+
PYTHON: "C:\\Python38-x64"
34+
2935
install:
3036
# https://github.com/pypa/virtualenv/issues/1050
3137
- pip install -U git+https://github.com/pypa/virtualenv@e8163e83a92c9098f51d390289323232ece15e3b

pytest_twisted.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import inspect
3+
import sys
34
import warnings
45

56
import decorator
@@ -326,3 +327,18 @@ def pytest_configure(config):
326327
)(blockon)
327328

328329
reactor_installers[config.getoption("reactor")]()
330+
331+
332+
def _use_asyncio_selector_if_required(config):
333+
# https://twistedmatrix.com/trac/ticket/9766
334+
# https://github.com/pytest-dev/pytest-twisted/issues/80
335+
336+
if (
337+
config.getoption("reactor", "default") == "asyncio"
338+
and sys.platform == 'win32'
339+
and sys.version_info >= (3, 8)
340+
):
341+
import asyncio
342+
343+
selector_policy = asyncio.WindowsSelectorEventLoopPolicy()
344+
asyncio.set_event_loop_policy(selector_policy)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"Programming Language :: Python :: 3.5",
2929
"Programming Language :: Python :: 3.6",
3030
"Programming Language :: Python :: 3.7",
31+
"Programming Language :: Python :: 3.8",
3132
],
3233
entry_points={"pytest11": ["twisted = pytest_twisted"]},
3334
)

testing/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
import pytest
2+
import pytest_twisted
3+
4+
15
pytest_plugins = "_pytest.pytester"
6+
7+
8+
@pytest.hookimpl(tryfirst=True)
9+
def pytest_configure(config):
10+
pytest_twisted._use_asyncio_selector_if_required(config=config)

testing/test_basic.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5265
def skip_if_reactor_not(request, expected_reactor):
5366
actual_reactor = request.config.getoption("reactor", "default")
5467
if actual_reactor != expected_reactor:
@@ -630,10 +643,14 @@ def main():
630643
def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
631644
skip_if_reactor_not(request, "asyncio")
632645
conftest_file = """
646+
import pytest
633647
import pytest_twisted as pt
634648
from twisted.internet import defer
635649
650+
@pytest.hookimpl(tryfirst=True)
636651
def pytest_configure(config):
652+
pt._use_asyncio_selector_if_required(config=config)
653+
637654
pt.init_asyncio_reactor()
638655
d = defer.Deferred()
639656
@@ -659,6 +676,14 @@ def test_succeed():
659676
def test_wrong_reactor_with_asyncio(testdir, cmd_opts, request):
660677
skip_if_reactor_not(request, "asyncio")
661678
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+
662687
def pytest_addhooks():
663688
import twisted.internet.default
664689
twisted.internet.default.install()

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[tox]
22
envlist=
33
py{27,35}-defaultreactor
4-
py{35,36,37}-{default,qt5,asyncio}reactor
5-
win-py{35,36,37}-qt5reactor
4+
py{35,36,37,38}-{default,qt5,asyncio}reactor
5+
win-py{35,36,37,38}-qt5reactor
66
linting
77

88
[testenv]

0 commit comments

Comments
 (0)