Skip to content

Update testing etc for Python 3.8 #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ matrix:
- python: 3.7
dist: xenial
sudo: true
- python: 3.8
dist: xenial
sudo: true

addons:
apt:
Expand Down
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ environment:
- TOXENV: py37-defaultreactor, win-py37-qt5reactor, py37-asyncioreactor
PYTHON: "C:\\Python37-x64"

- TOXENV: py38-defaultreactor, win-py38-qt5reactor, py38-asyncioreactor
PYTHON: "C:\\Python38"

- TOXENV: py38-defaultreactor, win-py38-qt5reactor, py38-asyncioreactor
PYTHON: "C:\\Python38-x64"

install:
# https://github.com/pypa/virtualenv/issues/1050
- pip install -U git+https://github.com/pypa/virtualenv@e8163e83a92c9098f51d390289323232ece15e3b
Expand Down
15 changes: 15 additions & 0 deletions pytest_twisted.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import inspect
import sys
import warnings

import decorator
Expand Down Expand Up @@ -326,3 +327,17 @@ def pytest_configure(config):
)(blockon)

reactor_installers[config.getoption("reactor")]()


def use_asyncio_selector_if_required(config):
# https://twistedmatrix.com/trac/ticket/9766

if (
config.getoption("reactor", "default") == "asyncio"
and sys.platform == 'win32'
and sys.version_info >= (3, 8)
):
import asyncio

selector_policy = asyncio.WindowsSelectorEventLoopPolicy()
asyncio.set_event_loop_policy(selector_policy)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm writing up some docs on the topic too (and fixed the missing trailing newline) but it feels like there's some thing to provide users with that isn't copy/paste. But, this isn't a pytest-twisted issue... and it could be run regardless of version. I can't decide how I feel about this.

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
entry_points={"pytest11": ["twisted = pytest_twisted"]},
)
9 changes: 9 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
import pytest
import pytest_twisted


pytest_plugins = "_pytest.pytester"


@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
pytest_twisted.use_asyncio_selector_if_required(config=config)
25 changes: 25 additions & 0 deletions testing/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def format_run_result_output_for_assert(run_result):
)


@pytest.fixture(name="default_conftest", autouse=True)
def _default_conftest(testdir):
testdir.makeconftest(textwrap.dedent("""
import pytest
import pytest_twisted


@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
pytest_twisted.use_asyncio_selector_if_required(config=config)
"""))


def skip_if_reactor_not(request, expected_reactor):
actual_reactor = request.config.getoption("reactor", "default")
if actual_reactor != expected_reactor:
Expand Down Expand Up @@ -627,10 +640,14 @@ def main():
def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
skip_if_reactor_not(request, "asyncio")
conftest_file = """
import pytest
import pytest_twisted as pt
from twisted.internet import defer

@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
pt.use_asyncio_selector_if_required(config=config)

pt.init_asyncio_reactor()
d = defer.Deferred()

Expand All @@ -656,6 +673,14 @@ def test_succeed():
def test_wrong_reactor_with_asyncio(testdir, cmd_opts, request):
skip_if_reactor_not(request, "asyncio")
conftest_file = """
import pytest
import pytest_twisted


@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
pytest_twisted.use_asyncio_selector_if_required(config=config)

def pytest_addhooks():
import twisted.internet.default
twisted.internet.default.install()
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
envlist=
py{27,35}-defaultreactor
py{35,36,37}-{default,qt5,asyncio}reactor
win-py{35,36,37}-qt5reactor
py{35,36,37,38}-{default,qt5,asyncio}reactor
win-py{35,36,37,38}-qt5reactor
linting

[testenv]
Expand Down