From d3f3bf46bfabdfa8abe9e7b4e747159356d004eb Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 13:08:07 -0400 Subject: [PATCH 1/9] Add test that constructs a QWidget --- testing/test_basic.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/testing/test_basic.py b/testing/test_basic.py index f062d81..00dab87 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -309,3 +309,19 @@ def main(): assert_outcomes(rr, {"passed": 1, "failed": 1}) # test embedded mode: assert testdir.run(sys.executable, "runner.py").ret == 0 + + +@skip_if_reactor_not("qt5reactor") +def test_qwidget(testdir, cmd_opts): + conftest_file = """ + """ + testdir.makeconftest(conftest_file) + test_file = """ + from PyQt5 import QtWidgets + + def test_construct_qwidget(): + QtWidgets.QWidget() + """ + testdir.makepyfile(test_file) + rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts) + assert rr.ret == 0 From a35273f9865413f33a0d3b4ffb408d78fc479e01 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 13:18:46 -0400 Subject: [PATCH 2/9] Add qapp fixture --- testing/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_basic.py b/testing/test_basic.py index 00dab87..230afd2 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -319,7 +319,7 @@ def test_qwidget(testdir, cmd_opts): test_file = """ from PyQt5 import QtWidgets - def test_construct_qwidget(): + def test_construct_qwidget(qapp): QtWidgets.QWidget() """ testdir.makepyfile(test_file) From 5a2250ff0aecfb5ef92bacb5ecbd4f033ec54bb0 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 14:16:08 -0400 Subject: [PATCH 3/9] Test QWidget creation against qapp, qtbot, and nothing --- testing/test_basic.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/testing/test_basic.py b/testing/test_basic.py index 230afd2..ec07ab8 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -311,17 +311,18 @@ def main(): assert testdir.run(sys.executable, "runner.py").ret == 0 +qt_fixtures = ('qapp', 'qtbot') + + @skip_if_reactor_not("qt5reactor") -def test_qwidget(testdir, cmd_opts): - conftest_file = """ - """ - testdir.makeconftest(conftest_file) +@pytest.mark.parametrize("fixture", qt_fixtures, ids=qt_fixtures) +def test_qwidget(testdir, cmd_opts, fixture): test_file = """ from PyQt5 import QtWidgets - def test_construct_qwidget(qapp): + 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 From c7f82f715bff6f6ef3ed7db56a5b2b8f16649b06 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 14:38:25 -0400 Subject: [PATCH 4/9] Partial fix --- pytest_twisted.py | 5 ++++- testing/test_basic.py | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pytest_twisted.py b/pytest_twisted.py index 769c175..4ff948f 100644 --- a/pytest_twisted.py +++ b/pytest_twisted.py @@ -141,7 +141,10 @@ def init_default_reactor(): ) -def init_qt5_reactor(): +def init_qt5_reactor(request): + import pytestqt.plugin + next(pytestqt.plugin.qapp(pytestqt.plugin.qapp_args())) + import qt5reactor _install_reactor( diff --git a/testing/test_basic.py b/testing/test_basic.py index ec07ab8..aa5b49b 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -311,15 +311,20 @@ def main(): assert testdir.run(sys.executable, "runner.py").ret == 0 -qt_fixtures = ('qapp', 'qtbot') +qt_fixtures = ('qapp', 'qtbot', 'nothing') @skip_if_reactor_not("qt5reactor") @pytest.mark.parametrize("fixture", qt_fixtures, ids=qt_fixtures) def test_qwidget(testdir, cmd_opts, fixture): test_file = """ + import pytest from PyQt5 import QtWidgets + @pytest.fixture + def nothing(): + return + def test_construct_qwidget({fixture}): QtWidgets.QWidget() """.format(fixture=fixture) From 948ab6491db7a9ad6ab2f07d2cae0ac012828cd0 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 14:44:16 -0400 Subject: [PATCH 5/9] oops --- pytest_twisted.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_twisted.py b/pytest_twisted.py index 4ff948f..bebf2d9 100644 --- a/pytest_twisted.py +++ b/pytest_twisted.py @@ -141,7 +141,7 @@ def init_default_reactor(): ) -def init_qt5_reactor(request): +def init_qt5_reactor(): import pytestqt.plugin next(pytestqt.plugin.qapp(pytestqt.plugin.qapp_args())) From 715a33a95932fbff64b9cc828fcd107ca36b3b63 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 14:58:20 -0400 Subject: [PATCH 6/9] @pytest.mark.trylast pytest-twisted pytest_configure stuff --- pytest_twisted.py | 1 + testing/test_basic.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pytest_twisted.py b/pytest_twisted.py index bebf2d9..1d0c7fb 100644 --- a/pytest_twisted.py +++ b/pytest_twisted.py @@ -186,5 +186,6 @@ def pytest_addoption(parser): ) +@pytest.mark.trylast def pytest_configure(config): reactor_installers[config.getoption("reactor")]() diff --git a/testing/test_basic.py b/testing/test_basic.py index aa5b49b..d7dabf5 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -213,10 +213,12 @@ def test_succeed(): @skip_if_reactor_not("qt5reactor") def test_blockon_in_hook_with_qt5reactor(testdir, cmd_opts): 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() From 0812d2910c6a2d241f7a12785e1b3ba835813439 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 15:28:15 -0400 Subject: [PATCH 7/9] why did the exception move to stdout... hmm --- testing/test_basic.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testing/test_basic.py b/testing/test_basic.py index d7dabf5..5d4371e 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -207,7 +207,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() + ) @skip_if_reactor_not("qt5reactor") @@ -256,7 +260,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() + ) @skip_if_reactor_not("default") From 6f04ba3ad806b3b40602999e71c28633c36d81f9 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 25 Sep 2018 15:29:37 -0400 Subject: [PATCH 8/9] fix lint --- testing/test_basic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/test_basic.py b/testing/test_basic.py index 5d4371e..8bd42c2 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -209,8 +209,8 @@ def test_succeed(): rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts) error_text = "WrongReactorAlreadyInstalledError" assert ( - error_text in rr.stderr.str() - or error_text in rr.stdout.str() + error_text in rr.stderr.str() or + error_text in rr.stdout.str() ) @@ -262,8 +262,8 @@ def test_succeed(): rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts) error_text = "WrongReactorAlreadyInstalledError" assert ( - error_text in rr.stderr.str() - or error_text in rr.stdout.str() + error_text in rr.stderr.str() or + error_text in rr.stdout.str() ) From 97746b80f55877ae4ace08c3b0fb69b231c52ca6 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 26 Sep 2019 22:15:11 -0400 Subject: [PATCH 9/9] Update skip_if_reactor_not() tagging --- testing/test_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_basic.py b/testing/test_basic.py index f9cfe32..0318c25 100755 --- a/testing/test_basic.py +++ b/testing/test_basic.py @@ -670,9 +670,9 @@ def test_succeed(): qt_fixtures = ('qapp', 'qtbot', 'nothing') -@skip_if_reactor_not("qt5reactor") @pytest.mark.parametrize("fixture", qt_fixtures, ids=qt_fixtures) -def test_qwidget(testdir, cmd_opts, fixture): +def test_qwidget(testdir, cmd_opts, fixture, request): + skip_if_reactor_not(request, "qt5reactor") test_file = """ import pytest from PyQt5 import QtWidgets