diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 99a25635..d3d3c6a5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: hooks: - id: pyupgrade - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.12.0 + rev: 26.1.0 hooks: - id: black args: [--safe, --quiet] diff --git a/setup.py b/setup.py index a84a288d..8d26ad8c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ from setuptools import setup, find_packages - setup( name="pytest-qt", packages=find_packages(where="src"), diff --git a/src/pytestqt/modeltest.py b/src/pytestqt/modeltest.py index c47ee648..a8218393 100644 --- a/src/pytestqt/modeltest.py +++ b/src/pytestqt/modeltest.py @@ -46,7 +46,6 @@ from pytestqt.qt_compat import qt_api - _Changing = collections.namedtuple("_Changing", "parent, old_size, last, next") diff --git a/src/pytestqt/qt_compat.py b/src/pytestqt/qt_compat.py index 49c4e80e..d25e0a4e 100644 --- a/src/pytestqt/qt_compat.py +++ b/src/pytestqt/qt_compat.py @@ -14,7 +14,6 @@ import pytest - VersionTuple = namedtuple("VersionTuple", "qt_api, qt_api_version, runtime, compiled") QT_APIS = OrderedDict() diff --git a/tests/test_basics.py b/tests/test_basics.py index 49cde4bd..701529e0 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -26,25 +26,20 @@ def test_qapp_default_name(qapp): def test_qapp_name(testdir): - testdir.makepyfile( - """ + testdir.makepyfile(""" def test_name(qapp): assert qapp.applicationName() == "frobnicator" - """ - ) - testdir.makeini( - """ + """) + testdir.makeini(""" [pytest] qt_qapp_name = frobnicator - """ - ) + """) res = testdir.runpytest_subprocess() res.stdout.fnmatch_lines("*1 passed*") def test_qapp_cls(testdir): - testdir.makepyfile( - app=""" + testdir.makepyfile(app=""" from pytestqt.qt_compat import qt_api # Gets run before the plugin via conftest.py @@ -52,33 +47,27 @@ def test_qapp_cls(testdir): class CustomQApp(qt_api.QtWidgets.QApplication): pass - """ - ) - testdir.makeconftest( - """ + """) + testdir.makeconftest(""" import pytest from app import CustomQApp @pytest.fixture(scope="session") def qapp_cls(): return CustomQApp - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from app import CustomQApp def test_cls(qapp): assert isinstance(qapp, CustomQApp) - """ - ) + """) res = testdir.runpytest_subprocess() res.stdout.fnmatch_lines("*1 passed*") def test_qapp_reuse_existing(testdir): - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api app_instance = qt_api.QtWidgets.QApplication([]) @@ -86,15 +75,13 @@ def test_qapp_reuse_existing(testdir): def test_instances(qapp): assert qapp is app_instance assert qapp is qt_api.QtWidgets.QApplication.instance() - """ - ) + """) res = testdir.runpytest_subprocess() res.stdout.fnmatch_lines("*1 passed*") def test_qapp_reuse_wrong_type(testdir): - testdir.makeconftest( - """ + testdir.makeconftest(""" import pytest from pytestqt.qt_compat import qt_api @@ -107,18 +94,15 @@ class CustomQApp(qt_api.QtWidgets.QApplication): @pytest.fixture(scope="session") def qapp_cls(): return CustomQApp - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api app_instance = qt_api.QtWidgets.QApplication([]) def test_wrong_type(qapp): pass - """ - ) + """) res = testdir.runpytest_subprocess() res.stdout.fnmatch_lines( "*Existing QApplication <*.QtWidgets.QApplication* at 0x*> is not an " @@ -267,8 +251,7 @@ def test_event_processing_before_and_after_teardown(testdir): https://github.com/pytest-dev/pytest-qt/issues/67 """ - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @@ -303,8 +286,7 @@ def test_events(events_queue, fix, i): assert events_queue.events == [] events_queue.events.append('test event') events_queue.pop_later() - """ - ) + """) res = testdir.runpytest() res.stdout.fnmatch_lines(["*3 passed in*"]) @@ -340,8 +322,7 @@ def test_widgets_closed_before_fixtures(testdir): Ensure widgets added by "qtbot.add_widget" are closed before all other fixtures are teardown. (#106). """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -362,8 +343,7 @@ def widget(qtbot): def test_foo(widget): pass - """ - ) + """) result = testdir.runpytest() result.stdout.fnmatch_lines(["*= 1 passed in *"]) @@ -440,23 +420,17 @@ def test_qt_api_ini_config(testdir, monkeypatch, option_api): monkeypatch.delenv("PYTEST_QT_API", raising=False) - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_api={option_api} - """.format( - option_api=option_api - ) - ) + """.format(option_api=option_api)) - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest def test_foo(qtbot): pass - """ - ) + """) result = testdir.runpytest_subprocess() if qt_api.pytest_qt_api == option_api: @@ -475,25 +449,19 @@ def test_foo(qtbot): @pytest.mark.parametrize("envvar", ["pyqt5", "pyqt6", "pyside6"]) def test_qt_api_ini_config_with_envvar(testdir, monkeypatch, envvar): """ensure environment variable wins over config value if both are present""" - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_api={option_api} - """.format( - option_api="piecute" - ) - ) + """.format(option_api="piecute")) monkeypatch.setenv("PYTEST_QT_API", envvar) - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest def test_foo(qtbot): pass - """ - ) + """) result = testdir.runpytest_subprocess() if qt_api.pytest_qt_api == envvar: @@ -513,14 +481,12 @@ def test_invalid_qt_api_envvar(testdir, monkeypatch): """ Make sure the error message with an invalid PYQTEST_QT_API is correct. """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest def test_foo(qtbot): pass - """ - ) + """) monkeypatch.setenv("PYTEST_QT_API", "piecute") result = testdir.runpytest_subprocess() result.stderr.fnmatch_lines( @@ -532,21 +498,17 @@ def test_qapp_args(testdir): """ Test customizing of QApplication arguments. """ - testdir.makeconftest( - """ + testdir.makeconftest(""" import pytest @pytest.fixture(scope='session') def qapp_args(): return ['prog_name', '--test-arg'] - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" def test_args(qapp): assert '--test-arg' in list(qapp.arguments()) - """ - ) + """) result = testdir.runpytest_subprocess() result.stdout.fnmatch_lines(["*= 1 passed in *"]) @@ -556,13 +518,11 @@ def test_qapp_args_default(testdir): Test QApplication default arguments. """ - testdir.makepyfile( - """ + testdir.makepyfile(""" def test_args(qapp): args = qapp.arguments() assert args[0] == 'pytest-qt-qapp' - """ - ) + """) result = testdir.runpytest_subprocess() result.stdout.fnmatch_lines(["*= 1 passed in *"]) @@ -660,8 +620,7 @@ def test_before_close_func(testdir): """ import sys - testdir.makepyfile( - """ + testdir.makepyfile(""" import sys import pytest from pytestqt.qt_compat import qt_api @@ -679,8 +638,7 @@ def widget(qtbot): def test_foo(widget): pass - """ - ) + """) result = testdir.runpytest_inprocess() result.stdout.fnmatch_lines(["*= 1 passed in *"]) assert sys.pytest_qt_widget_closed diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 9347b9d8..eb35c813 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -29,8 +29,7 @@ def test_catch_exceptions_in_virtual_methods(testdir, raise_error): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api class Receiver(qt_api.QtCore.QObject): @@ -52,10 +51,7 @@ def test_exceptions(qtbot): app.sendEvent(v, qt_api.QtCore.QEvent(qt_api.QtCore.QEvent.Type.User)) app.processEvents() - """.format( - raise_error=raise_error - ) - ) + """.format(raise_error=raise_error)) result = testdir.runpytest() if raise_error: if has_pyside6_exception_capture(): @@ -125,14 +121,11 @@ def test_no_capture(testdir, no_capture_by_marker): marker_code = "@pytest.mark.qt_no_exception_capture" else: marker_code = "" - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_no_exception_capture = 1 - """ - ) - testdir.makepyfile( - f""" + """) + testdir.makepyfile(f""" import pytest import sys from pytestqt.qt_compat import qt_api @@ -150,8 +143,7 @@ def test_widget(qtbot): w = MyWidget() qtbot.addWidget(w) qtbot.mouseClick(w, qt_api.QtCore.Qt.MouseButton.LeftButton) - """ - ) + """) res = testdir.runpytest() res.stdout.fnmatch_lines(["*1 passed*"]) @@ -162,8 +154,7 @@ def test_no_capture_preserves_custom_excepthook(testdir): :type testdir: TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest import sys from pytestqt.qt_compat import qt_api @@ -179,8 +170,7 @@ def test_no_capture(qtbot): def test_capture(qtbot): assert sys.excepthook is not custom_excepthook - """ - ) + """) res = testdir.runpytest() res.stdout.fnmatch_lines(["*2 passed*"]) @@ -191,8 +181,7 @@ def test_exception_capture_on_call(testdir): :type testdir: TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -205,8 +194,7 @@ def test_widget(qtbot, qapp): w = MyWidget() qapp.postEvent(w, qt_api.QtCore.QEvent(QEvent.Type.User)) qapp.processEvents() - """ - ) + """) res = testdir.runpytest("-s") res.stdout.fnmatch_lines(["*RuntimeError('event processed')*", "*1 failed*"]) @@ -217,8 +205,7 @@ def test_exception_capture_on_widget_close(testdir): :type testdir: TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -231,8 +218,7 @@ def test_widget(qtbot, qapp): w = MyWidget() test_widget.w = w # keep it alive qtbot.addWidget(w) - """ - ) + """) res = testdir.runpytest("-s") res.stdout.fnmatch_lines(["*RuntimeError('close error')*", "*1 error*"]) @@ -252,8 +238,7 @@ def test_exception_capture_on_fixture_setup_and_teardown(testdir, mode): setup_code = "" teardown_code = "send_event(w, qapp)" - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -278,10 +263,7 @@ def send_event(w, qapp): def test_capture(widget): pass - """.format( - setup_code=setup_code, teardown_code=teardown_code - ) - ) + """.format(setup_code=setup_code, teardown_code=teardown_code)) res = testdir.runpytest("-s") res.stdout.fnmatch_lines( [ @@ -319,8 +301,7 @@ def test_capture_exceptions_qtbot_context_manager(testdir): """Test capturing exceptions in a block by using `capture_exceptions` method provided by `qtbot`. """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -342,8 +323,7 @@ def raise_on_event(): assert len(exceptions) == 1 assert str(exceptions[0][1]) == "error" - """ - ) + """) result = testdir.runpytest() result.stdout.fnmatch_lines(["*1 passed*"]) @@ -376,8 +356,7 @@ def test_exceptions_dont_leak(testdir): """ Ensure exceptions are cleared when an exception occurs and don't leak (#187). """ - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import gc import weakref @@ -402,7 +381,6 @@ def test_2(qapp): assert called gc.collect() assert weak_ref() is None - """ - ) + """) result = testdir.runpytest() result.stdout.fnmatch_lines(["*1 failed, 1 passed*"]) diff --git a/tests/test_logging.py b/tests/test_logging.py index f1fafbdb..5ea198a8 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -4,7 +4,6 @@ from pytestqt.qt_compat import qt_api - # qInfo is not exposed by PySide6 < 6.8.2 (#225) HAS_QINFO = qt_api.qInfo is not None @@ -17,8 +16,7 @@ def test_basic_logging(testdir, test_succeeds, qt_log): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - f""" + testdir.makepyfile(f""" import sys from pytestqt.qt_compat import qt_api @@ -36,8 +34,7 @@ def test_types(): qt_api.qWarning('this is a WARNING message') qt_api.qCritical('this is a CRITICAL message') assert {test_succeeds} - """ - ) + """) res = testdir.runpytest(*(["--no-qt-log"] if not qt_log else [])) if test_succeeds: assert "Captured Qt messages" not in res.stdout.str() @@ -99,15 +96,13 @@ def test_fixture_with_logging_disabled(testdir, arg): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api def test_types(qtlog): qt_api.qWarning('message') assert qtlog.records == [] - """ - ) + """) res = testdir.runpytest(arg) res.stdout.fnmatch_lines("*1 passed*") @@ -119,28 +114,22 @@ def test_disable_qtlog_context_manager(testdir, use_context_manager): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = CRITICAL - """ - ) + """) if use_context_manager: code = "with qtlog.disabled():" else: code = "if 1:" - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api def test_1(qtlog): {code} qt_api.qCritical('message') - """.format( - code=code - ) - ) + """.format(code=code)) res = testdir.inline_run() passed = 1 if use_context_manager else 0 res.assertoutcome(passed=passed, failed=int(not passed)) @@ -153,25 +142,19 @@ def test_disable_qtlog_mark(testdir, use_mark): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = CRITICAL - """ - ) + """) mark = "@pytest.mark.no_qt_log" if use_mark else "" - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest {mark} def test_1(): qt_api.qCritical('message') - """.format( - mark=mark - ) - ) + """.format(mark=mark)) res = testdir.inline_run() passed = 1 if use_mark else 0 res.assertoutcome(passed=passed, failed=int(not passed)) @@ -183,14 +166,12 @@ def test_logging_formatting(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api def test_types(): qt_api.qWarning('this is a WARNING message') assert 0 - """ - ) + """) f = "{rec.type_name} {rec.log_type_name} {rec.when:%Y-%m-%d}: {rec.message}" res = testdir.runpytest(f"--qt-log-format={f}") today = "{:%Y-%m-%d}".format(datetime.datetime.now()) @@ -211,16 +192,11 @@ def test_logging_fails_tests(testdir, level, expect_passes): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = {level} - """.format( - level=level - ) - ) - testdir.makepyfile( - """ + """.format(level=level)) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api def test_1(): qt_api.qDebug('this is a DEBUG message') @@ -230,8 +206,7 @@ def test_3(): qt_api.qCritical('this is a CRITICAL message') def test_4(): assert 1 - """ - ) + """) res = testdir.runpytest() lines = [] if level != "NO": @@ -253,21 +228,17 @@ def test_logging_fails_tests_mark(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = CRITICAL - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qWarning import pytest @pytest.mark.qt_log_level_fail('WARNING') def test_1(): qWarning('message') - """ - ) + """) res = testdir.inline_run() res.assertoutcome(failed=1) @@ -278,17 +249,14 @@ def test_logging_fails_ignore(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = CRITICAL qt_log_ignore = WM_DESTROY.*sent WM_PAINT not handled - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @@ -302,8 +270,7 @@ def test3(): def test4(): qt_api.qCritical('WM_PAINT not handled') qt_api.qCritical('another critical message') - """ - ) + """) res = testdir.runpytest() lines = [ # test1 fails because it has emitted a CRITICAL message and that message @@ -336,25 +303,19 @@ def test_logging_mark_with_extend(testdir, message, marker_args): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = CRITICAL qt_log_ignore = match-global - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @pytest.mark.qt_log_ignore({marker_args}) def test1(): qt_api.qCritical('{message}') - """.format( - message=message, marker_args=marker_args - ) - ) + """.format(message=message, marker_args=marker_args)) res = testdir.inline_run() res.assertoutcome(passed=1, failed=0) @@ -368,25 +329,19 @@ def test_logging_mark_without_extend(testdir, message, error_expected): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = CRITICAL qt_log_ignore = match-global - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @pytest.mark.qt_log_ignore('match-mark', extend=False) def test1(): qt_api.qCritical('{message}') - """.format( - message=message - ) - ) + """.format(message=message)) res = testdir.inline_run() if error_expected: @@ -401,15 +356,13 @@ def test_logging_mark_with_invalid_argument(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest @pytest.mark.qt_log_ignore('match-mark', does_not_exist=True) def test1(): pass - """ - ) + """) res = testdir.runpytest() lines = [ "*= ERRORS =*", @@ -433,18 +386,14 @@ def test_logging_fails_ignore_mark_multiple(testdir, apply_mark): mark = '@pytest.mark.qt_log_ignore("WM_DESTROY", "WM_PAINT")' else: mark = "" - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @pytest.mark.qt_log_level_fail('CRITICAL') {mark} def test1(): qt_api.qCritical('WM_PAINT was sent') - """.format( - mark=mark - ) - ) + """.format(mark=mark)) res = testdir.inline_run() passed = 1 if apply_mark else 0 res.assertoutcome(passed=passed, failed=int(not passed)) @@ -457,22 +406,18 @@ def test_lineno_failure(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = WARNING - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api def test_foo(): assert foo() == 10 def foo(): qt_api.qWarning('this is a WARNING message') return 10 - """ - ) + """) res = testdir.runpytest() if qt_api.is_pyqt: res.stdout.fnmatch_lines( @@ -501,8 +446,7 @@ def test_context_none(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api def test_foo(request): @@ -511,8 +455,7 @@ def test_foo(request): log_capture._handle_with_context(qt_api.QtCore.QtMsgType.QtWarningMsg, context, "WARNING message") assert 0 - """ - ) + """) res = testdir.runpytest() assert "*None:None:0:*" not in str(res.stdout) res.stdout.fnmatch_lines(["QtWarningMsg: WARNING message"]) @@ -526,8 +469,7 @@ def test_logging_broken_makereport(testdir): :type testdir: _pytest.pytester.TmpTestdir """ - testdir.makepyfile( - conftest=""" + testdir.makepyfile(conftest=""" import pytest @pytest.hookimpl(hookwrapper=True, tryfirst=True) @@ -535,13 +477,10 @@ def pytest_runtest_makereport(call): if call.when == 'call': raise Exception("This should not be hidden") yield - """ - ) - p = testdir.makepyfile( - """ + """) + p = testdir.makepyfile(""" def test_foo(): pass - """ - ) + """) res = testdir.runpytest_subprocess(p) res.stdout.fnmatch_lines(["*This should not be hidden*"]) diff --git a/tests/test_modeltest.py b/tests/test_modeltest.py index 7ae2a9d3..f4dfa94f 100644 --- a/tests/test_modeltest.py +++ b/tests/test_modeltest.py @@ -316,8 +316,7 @@ def parent(self, index): @pytest.mark.skipif(not modeltest.HAS_QT_TESTER, reason="No Qt modeltester available") def test_qt_tester_valid(testdir): - testdir.makepyfile( - """ + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api from pytestqt import modeltest @@ -327,22 +326,18 @@ def test_qt_tester_valid(testdir): def test_ok(qtmodeltester): model = qt_api.QtGui.QStandardItemModel() qtmodeltester.check(model) - """ - ) + """) res = testdir.inline_run() res.assertoutcome(passed=1, failed=0) @pytest.mark.skipif(not modeltest.HAS_QT_TESTER, reason="No Qt modeltester available") def test_qt_tester_invalid(testdir): - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_log_level_fail = NO - """ - ) - testdir.makepyfile( - """ + """) + testdir.makepyfile(""" from pytestqt.qt_compat import qt_api from pytestqt import modeltest @@ -369,8 +364,7 @@ def parent(self, index): def test_ok(qtmodeltester): model = Model() qtmodeltester.check(model) - """ - ) + """) res = testdir.runpytest() res.stdout.fnmatch_lines( [ diff --git a/tests/test_qtest_proxies.py b/tests/test_qtest_proxies.py index f514126b..23492fc2 100644 --- a/tests/test_qtest_proxies.py +++ b/tests/test_qtest_proxies.py @@ -36,8 +36,7 @@ def test_keyToAscii_not_available_on_pyqt(testdir): Test that qtbot.keyToAscii() is not available on PyQt5 and calling the method raises a NotImplementedError. """ - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -46,7 +45,6 @@ def test_foo(qtbot): qtbot.add_widget(widget) with pytest.raises(NotImplementedError): qtbot.keyToAscii(qt_api.QtCore.Qt.Key.Key_Escape) - """ - ) + """) result = testdir.runpytest() result.stdout.fnmatch_lines(["*= 1 passed in *"]) diff --git a/tests/test_wait_signal.py b/tests/test_wait_signal.py index 8903dd52..72d00ed6 100644 --- a/tests/test_wait_signal.py +++ b/tests/test_wait_signal.py @@ -150,15 +150,12 @@ def test_zero_timeout(qtbot, timer, delayed, signaller): ) def test_raising(qtbot, testdir, configval, raises): if configval is not None: - testdir.makeini( - f""" + testdir.makeini(f""" [pytest] qt_default_raising = {configval} - """ - ) + """) - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -170,8 +167,7 @@ def test_foo(qtbot): with qtbot.waitSignal(signaller.signal, timeout=10): pass - """ - ) + """) res = testdir.runpytest() @@ -182,15 +178,12 @@ def test_foo(qtbot): def test_raising_by_default_overridden(qtbot, testdir): - testdir.makeini( - """ + testdir.makeini(""" [pytest] qt_default_raising = false - """ - ) + """) - testdir.makepyfile( - """ + testdir.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -203,8 +196,7 @@ def test_foo(qtbot): with qtbot.waitSignal(signal, raising=True, timeout=10) as blocker: pass - """ - ) + """) res = testdir.runpytest() res.stdout.fnmatch_lines(["*1 failed*"]) @@ -1398,8 +1390,7 @@ def test_signal_raised_from_thread( Extracted from https://github.com/pytest-dev/pytest-qt/issues/586 """ - pytester.makepyfile( - f""" + pytester.makepyfile(f""" import pytest from pytestqt.qt_compat import qt_api @@ -1429,8 +1420,7 @@ def test_thread(qtbot, capfd, _): if {check_stderr}: # check_stderr out, err = capfd.readouterr() assert not err - """ - ) + """) res = pytester.runpytest_subprocess("-x", "-s") outcomes = res.parseoutcomes() @@ -1459,8 +1449,7 @@ def test_callback_in_thread(pytester: pytest.Pytester) -> None: # triggers after ~30k runs (~44s). Thus, we skip this test by default. count = 50_000 - pytester.makepyfile( - f""" + pytester.makepyfile(f""" import pytest from pytestqt.qt_compat import qt_api @@ -1487,8 +1476,7 @@ def test_thread(qtbot, _): finally: thread.quit() thread.wait() - """ - ) + """) res = pytester.runpytest_subprocess("-x") outcomes = res.parseoutcomes()