Skip to content
4 changes: 4 additions & 0 deletions pytest_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def init_default_reactor():


def init_qt5_reactor():
import pytestqt.plugin
next(pytestqt.plugin.qapp(pytestqt.plugin.qapp_args()))

import qt5reactor

_install_reactor(
Expand Down Expand Up @@ -316,6 +319,7 @@ def pytest_addoption(parser):
)


@pytest.mark.trylast
def pytest_configure(config):
pytest.inlineCallbacks = _deprecate(
deprecated='pytest.inlineCallbacks',
Expand Down
36 changes: 34 additions & 2 deletions testing/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,16 +536,22 @@ def test_succeed():
"""
testdir.makepyfile(test_file)
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
error_text = "WrongReactorAlreadyInstalledError"
assert (
error_text in rr.stderr.str() or
error_text in rr.stdout.str()
)


def test_blockon_in_hook_with_qt5reactor(testdir, cmd_opts, request):
skip_if_reactor_not(request, "qt5reactor")
conftest_file = """
import pytest
import pytest_twisted as pt
import pytestqt
from twisted.internet import defer

@pytest.mark.trylast
def pytest_configure(config):
pt.init_qt5_reactor()
d = defer.Deferred()
Expand Down Expand Up @@ -583,7 +589,11 @@ def test_succeed():
"""
testdir.makepyfile(test_file)
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
error_text = "WrongReactorAlreadyInstalledError"
assert (
error_text in rr.stderr.str() or
error_text in rr.stdout.str()
)


def test_pytest_from_reactor_thread(testdir, request):
Expand Down Expand Up @@ -696,3 +706,25 @@ def test_succeed():
testdir.makepyfile(test_file)
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()


qt_fixtures = ('qapp', 'qtbot', 'nothing')


@pytest.mark.parametrize("fixture", qt_fixtures, ids=qt_fixtures)
def test_qwidget(testdir, cmd_opts, fixture, request):
skip_if_reactor_not(request, "qt5reactor")
test_file = """
import pytest
from PyQt5 import QtWidgets

@pytest.fixture
def nothing():
return

def test_construct_qwidget({fixture}):
QtWidgets.QWidget()
""".format(fixture=fixture)
testdir.makepyfile(test_file)
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
assert rr.ret == 0