From b7f5487e625306fb72b8198613e32e7035c4646c Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 29 Sep 2026 13:39:57 +0200 Subject: [PATCH 1/2] Use tmp_path instead of tmpdir in tests Co-Authored-By: Claude Opus 5.5 --- tests/test_basics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_basics.py b/tests/test_basics.py index 65a5517..63c9199 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -305,10 +305,10 @@ def test_header(testdir, monkeypatch): ) -def test_qvariant(tmpdir): +def test_qvariant(tmp_path): """Test that QVariant works in the same way across all supported Qt bindings.""" settings = qt_api.QtCore.QSettings( - str(tmpdir / "foo.ini"), qt_api.QtCore.QSettings.Format.IniFormat + str(tmp_path / "foo.ini"), qt_api.QtCore.QSettings.Format.IniFormat ) settings.setValue("int", 42) settings.setValue("str", "Hello") From ceb190bb607211e4dd849260ebd79a67eee32ab6 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 29 Sep 2026 13:39:57 +0200 Subject: [PATCH 2/2] Use pytester instead of testdir in tests Co-Authored-By: Claude Opus 5.5 --- pyproject.toml | 2 +- tests/test_basics.py | 92 ++++++++++++------------ tests/test_exceptions.py | 62 ++++++++-------- tests/test_logging.py | 138 ++++++++++++++++++------------------ tests/test_modeltest.py | 14 ++-- tests/test_qtest_proxies.py | 6 +- tests/test_wait_signal.py | 16 ++--- 7 files changed, 165 insertions(+), 165 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a3df841..d151311 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ ] urls = {Homepage = "http://github.com/pytest-dev/pytest-qt"} requires-python = ">=3.9" -dependencies = ["pytest", "pluggy>=1.1", "typing_extensions"] +dependencies = ["pytest>=6.2", "pluggy>=1.1", "typing_extensions"] dynamic = ["version"] [project.readme] diff --git a/tests/test_basics.py b/tests/test_basics.py index 63c9199..5f9fa01 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -25,21 +25,21 @@ def test_qapp_default_name(qapp): assert qapp.applicationName() == "pytest-qt-qapp" -def test_qapp_name(testdir): - testdir.makepyfile(""" +def test_qapp_name(pytester): + pytester.makepyfile(""" def test_name(qapp): assert qapp.applicationName() == "frobnicator" """) - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_qapp_name = frobnicator """) - res = testdir.runpytest_subprocess() + res = pytester.runpytest_subprocess() res.stdout.fnmatch_lines("*1 passed*") -def test_qapp_cls(testdir): - testdir.makepyfile( +def test_qapp_cls(pytester): + pytester.makepyfile( app=""" from pytestqt.qt_compat import qt_api @@ -50,7 +50,7 @@ class CustomQApp(qt_api.QtWidgets.QApplication): pass """ ) - testdir.makeconftest(""" + pytester.makeconftest(""" import pytest from app import CustomQApp @@ -58,18 +58,18 @@ class CustomQApp(qt_api.QtWidgets.QApplication): def qapp_cls(): return CustomQApp """) - testdir.makepyfile(""" + pytester.makepyfile(""" from app import CustomQApp def test_cls(qapp): assert isinstance(qapp, CustomQApp) """) - res = testdir.runpytest_subprocess() + res = pytester.runpytest_subprocess() res.stdout.fnmatch_lines("*1 passed*") -def test_qapp_reuse_existing(testdir): - testdir.makepyfile(""" +def test_qapp_reuse_existing(pytester): + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api app_instance = qt_api.QtWidgets.QApplication([]) @@ -78,12 +78,12 @@ def test_instances(qapp): assert qapp is app_instance assert qapp is qt_api.QtWidgets.QApplication.instance() """) - res = testdir.runpytest_subprocess() + res = pytester.runpytest_subprocess() res.stdout.fnmatch_lines("*1 passed*") -def test_qapp_reuse_wrong_type(testdir): - testdir.makeconftest(""" +def test_qapp_reuse_wrong_type(pytester): + pytester.makeconftest(""" import pytest from pytestqt.qt_compat import qt_api @@ -97,7 +97,7 @@ class CustomQApp(qt_api.QtWidgets.QApplication): def qapp_cls(): return CustomQApp """) - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api app_instance = qt_api.QtWidgets.QApplication([]) @@ -105,7 +105,7 @@ def qapp_cls(): def test_wrong_type(qapp): pass """) - res = testdir.runpytest_subprocess() + res = pytester.runpytest_subprocess() res.stdout.fnmatch_lines( "*Existing QApplication <*.QtWidgets.QApplication* at 0x*> is not an " "instance of qapp_cls: " @@ -242,7 +242,7 @@ def test_widget_kept_as_weakref(qtbot): assert widget() is None -def test_event_processing_before_and_after_teardown(testdir): +def test_event_processing_before_and_after_teardown(pytester): """ Make sure events are processed before and after fixtures are torn down. @@ -253,7 +253,7 @@ def test_event_processing_before_and_after_teardown(testdir): https://github.com/pytest-dev/pytest-qt/issues/67 """ - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @@ -289,17 +289,17 @@ def test_events(events_queue, fix, i): events_queue.events.append('test event') events_queue.pop_later() """) - res = testdir.runpytest() + res = pytester.runpytest() res.stdout.fnmatch_lines(["*3 passed in*"]) -def test_header(testdir, monkeypatch): +def test_header(pytester, monkeypatch): monkeypatch.setattr( qt_api, "get_versions", lambda: qt_compat.VersionTuple("PyQtAPI", "1.0", "2.5", "3.5"), ) - res = testdir.runpytest_inprocess() + res = pytester.runpytest_inprocess() res.stdout.fnmatch_lines( ["*test session starts*", "PyQtAPI 1.0 -- Qt runtime 2.5 -- Qt compiled 3.5"] ) @@ -319,12 +319,12 @@ def test_qvariant(tmp_path): assert settings.value("empty") is None -def test_widgets_closed_before_fixtures(testdir): +def test_widgets_closed_before_fixtures(pytester): """ Ensure widgets added by "qtbot.add_widget" are closed before all other fixtures are teardown. (#106). """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -346,7 +346,7 @@ def widget(qtbot): def test_foo(widget): pass """) - result = testdir.runpytest() + result = pytester.runpytest() result.stdout.fnmatch_lines(["*= 1 passed in *"]) @@ -414,7 +414,7 @@ def test_parse_ini_boolean_invalid(): @pytest.mark.parametrize("option_api", ["pyqt5", "pyqt6", "pyside6"]) -def test_qt_api_ini_config(testdir, monkeypatch, option_api): +def test_qt_api_ini_config(pytester, monkeypatch, option_api): """ Test qt_api ini option handling. """ @@ -422,21 +422,21 @@ def test_qt_api_ini_config(testdir, monkeypatch, option_api): monkeypatch.delenv("PYTEST_QT_API", raising=False) - testdir.makeini( + pytester.makeini( """ [pytest] qt_api={option_api} """.format(option_api=option_api) ) - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest def test_foo(qtbot): pass """) - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() if qt_api.pytest_qt_api == option_api: result.stdout.fnmatch_lines(["* 1 passed in *"]) else: @@ -451,9 +451,9 @@ def test_foo(qtbot): @pytest.mark.parametrize("envvar", ["pyqt5", "pyqt6", "pyside6"]) -def test_qt_api_ini_config_with_envvar(testdir, monkeypatch, envvar): +def test_qt_api_ini_config_with_envvar(pytester, monkeypatch, envvar): """ensure environment variable wins over config value if both are present""" - testdir.makeini( + pytester.makeini( """ [pytest] qt_api={option_api} @@ -462,14 +462,14 @@ def test_qt_api_ini_config_with_envvar(testdir, monkeypatch, envvar): monkeypatch.setenv("PYTEST_QT_API", envvar) - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest def test_foo(qtbot): pass """) - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() if qt_api.pytest_qt_api == envvar: result.stdout.fnmatch_lines(["* 1 passed in *"]) else: @@ -483,53 +483,53 @@ def test_foo(qtbot): result.stderr.fnmatch_lines(["*ModuleNotFoundError:*"]) -def test_invalid_qt_api_envvar(testdir, monkeypatch): +def test_invalid_qt_api_envvar(pytester, monkeypatch): """ Make sure the error message with an invalid PYQTEST_QT_API is correct. """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest def test_foo(qtbot): pass """) monkeypatch.setenv("PYTEST_QT_API", "piecute") - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() result.stderr.fnmatch_lines( ["* Invalid value for $PYTEST_QT_API: piecute, expected one of *"] ) -def test_qapp_args(testdir): +def test_qapp_args(pytester): """ Test customizing of QApplication arguments. """ - testdir.makeconftest(""" + pytester.makeconftest(""" import pytest @pytest.fixture(scope='session') def qapp_args(): return ['prog_name', '--test-arg'] """) - testdir.makepyfile(""" + pytester.makepyfile(""" def test_args(qapp): assert '--test-arg' in list(qapp.arguments()) """) - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() result.stdout.fnmatch_lines(["*= 1 passed in *"]) -def test_qapp_args_default(testdir): +def test_qapp_args_default(pytester): """ Test QApplication default arguments. """ - testdir.makepyfile(""" + pytester.makepyfile(""" def test_args(qapp): args = qapp.arguments() assert args[0] == 'pytest-qt-qapp' """) - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() result.stdout.fnmatch_lines(["*= 1 passed in *"]) @@ -620,13 +620,13 @@ def _fake_is_library_loaded(name, *args): assert qt_api.pytest_qt_api == option_api -def test_before_close_func(testdir): +def test_before_close_func(pytester): """ Test the `before_close_func` argument of qtbot.addWidget. """ import sys - testdir.makepyfile(""" + pytester.makepyfile(""" import sys import pytest from pytestqt.qt_compat import qt_api @@ -645,12 +645,12 @@ def widget(qtbot): def test_foo(widget): pass """) - result = testdir.runpytest_inprocess() + result = pytester.runpytest_inprocess() result.stdout.fnmatch_lines(["*= 1 passed in *"]) assert sys.pytest_qt_widget_closed -def test_addwidget_typeerror(testdir, qtbot): +def test_addwidget_typeerror(pytester, qtbot): """ Make sure addWidget catches type errors early. """ diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 1919741..9262804 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -22,14 +22,14 @@ def has_pyside6_exception_capture(): @pytest.mark.parametrize("raise_error", [False, True]) -def test_catch_exceptions_in_virtual_methods(testdir, raise_error): +def test_catch_exceptions_in_virtual_methods(pytester, raise_error): """ Catch exceptions that happen inside Qt's event loop and make the tests fail if any. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile( + pytester.makepyfile( """ from pytestqt.qt_compat import qt_api @@ -54,7 +54,7 @@ def test_exceptions(qtbot): """.format(raise_error=raise_error) ) - result = testdir.runpytest() + result = pytester.runpytest() if raise_error: if has_pyside6_exception_capture(): # PySide6 automatically captures exceptions during the event loop, @@ -112,22 +112,22 @@ def test_format_captured_exceptions_chained(): @pytest.mark.parametrize("no_capture_by_marker", [True, False]) @exception_capture_pyside6 -def test_no_capture(testdir, no_capture_by_marker): +def test_no_capture(pytester, no_capture_by_marker): """ Make sure options that disable exception capture are working (either marker or ini configuration value). - :type testdir: TmpTestdir + :type pytester: TmpTestdir """ if no_capture_by_marker: marker_code = "@pytest.mark.qt_no_exception_capture" else: marker_code = "" - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_no_exception_capture = 1 """) - testdir.makepyfile(f""" + pytester.makepyfile(f""" import pytest import sys from pytestqt.qt_compat import qt_api @@ -146,17 +146,17 @@ def test_widget(qtbot): qtbot.addWidget(w) qtbot.mouseClick(w, qt_api.QtCore.Qt.MouseButton.LeftButton) """) - res = testdir.runpytest() + res = pytester.runpytest() res.stdout.fnmatch_lines(["*1 passed*"]) -def test_no_capture_preserves_custom_excepthook(testdir): +def test_no_capture_preserves_custom_excepthook(pytester): """ Capturing must leave custom excepthooks alone when disabled. - :type testdir: TmpTestdir + :type pytester: TmpTestdir """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest import sys from pytestqt.qt_compat import qt_api @@ -173,17 +173,17 @@ def test_no_capture(qtbot): def test_capture(qtbot): assert sys.excepthook is not custom_excepthook """) - res = testdir.runpytest() + res = pytester.runpytest() res.stdout.fnmatch_lines(["*2 passed*"]) -def test_exception_capture_on_call(testdir): +def test_exception_capture_on_call(pytester): """ Exceptions should also be captured during test execution. - :type testdir: TmpTestdir + :type pytester: TmpTestdir """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -197,17 +197,17 @@ def test_widget(qtbot, qapp): qapp.postEvent(w, qt_api.QtCore.QEvent(QEvent.Type.User)) qapp.processEvents() """) - res = testdir.runpytest("-s") + res = pytester.runpytest("-s") res.stdout.fnmatch_lines(["*RuntimeError('event processed')*", "*1 failed*"]) -def test_exception_capture_on_widget_close(testdir): +def test_exception_capture_on_widget_close(pytester): """ Exceptions should also be captured when widget is being closed. - :type testdir: TmpTestdir + :type pytester: TmpTestdir """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -221,17 +221,17 @@ def test_widget(qtbot, qapp): test_widget.w = w # keep it alive qtbot.addWidget(w) """) - res = testdir.runpytest("-s") + res = pytester.runpytest("-s") res.stdout.fnmatch_lines(["*RuntimeError('close error')*", "*1 error*"]) @pytest.mark.parametrize("mode", ["setup", "teardown"]) -def test_exception_capture_on_fixture_setup_and_teardown(testdir, mode): +def test_exception_capture_on_fixture_setup_and_teardown(pytester, mode): """ Setup/teardown exception capturing as early/late as possible to catch all exceptions, even from other fixtures (#105). - :type testdir: TmpTestdir + :type pytester: TmpTestdir """ if mode == "setup": setup_code = "send_event(w, qapp)" @@ -240,7 +240,7 @@ def test_exception_capture_on_fixture_setup_and_teardown(testdir, mode): setup_code = "" teardown_code = "send_event(w, qapp)" - testdir.makepyfile( + pytester.makepyfile( """ import pytest from pytestqt.qt_compat import qt_api @@ -268,7 +268,7 @@ def test_capture(widget): pass """.format(setup_code=setup_code, teardown_code=teardown_code) ) - res = testdir.runpytest("-s") + res = pytester.runpytest("-s") res.stdout.fnmatch_lines( [ "*__ ERROR at %s of test_capture __*" % mode, @@ -301,11 +301,11 @@ def event(self, ev): assert [str(e) for (t, e, tb) in exceptions] == ["mistakes were made"] -def test_capture_exceptions_qtbot_context_manager(testdir): +def test_capture_exceptions_qtbot_context_manager(pytester): """Test capturing exceptions in a block by using `capture_exceptions` method provided by `qtbot`. """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -328,7 +328,7 @@ def raise_on_event(): assert len(exceptions) == 1 assert str(exceptions[0][1]) == "error" """) - result = testdir.runpytest() + result = pytester.runpytest() result.stdout.fnmatch_lines(["*1 passed*"]) @@ -356,11 +356,11 @@ def event(self, ev): @exception_capture_pyside6 -def test_exceptions_dont_leak(testdir): +def test_exceptions_dont_leak(pytester): """ Ensure exceptions are cleared when an exception occurs and don't leak (#187). """ - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api import gc import weakref @@ -386,5 +386,5 @@ def test_2(qapp): gc.collect() assert weak_ref() is None """) - result = testdir.runpytest() + result = pytester.runpytest() result.stdout.fnmatch_lines(["*1 failed, 1 passed*"]) diff --git a/tests/test_logging.py b/tests/test_logging.py index 6d3094f..a804f2d 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -10,13 +10,13 @@ @pytest.mark.parametrize("test_succeeds", [True, False]) @pytest.mark.parametrize("qt_log", [True, False]) -def test_basic_logging(testdir, test_succeeds, qt_log): +def test_basic_logging(pytester, test_succeeds, qt_log): """ Test Qt logging capture output. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile(f""" + pytester.makepyfile(f""" import sys from pytestqt.qt_compat import qt_api @@ -35,7 +35,7 @@ def test_types(): qt_api.qCritical('this is a CRITICAL message') assert {test_succeeds} """) - res = testdir.runpytest(*(["--no-qt-log"] if not qt_log else [])) + res = pytester.runpytest(*(["--no-qt-log"] if not qt_log else [])) if test_succeeds: assert "Captured Qt messages" not in res.stdout.str() assert "Captured stderr call" not in res.stdout.str() @@ -89,32 +89,32 @@ def test_qtlog_fixture(qtlog): @pytest.mark.parametrize("arg", ["--no-qt-log", "--capture=no", "-s"]) -def test_fixture_with_logging_disabled(testdir, arg): +def test_fixture_with_logging_disabled(pytester, arg): """ Test that qtlog fixture doesn't capture anything if logging is disabled in the command line. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api def test_types(qtlog): qt_api.qWarning('message') assert qtlog.records == [] """) - res = testdir.runpytest(arg) + res = pytester.runpytest(arg) res.stdout.fnmatch_lines("*1 passed*") @pytest.mark.parametrize("use_context_manager", [True, False]) -def test_disable_qtlog_context_manager(testdir, use_context_manager): +def test_disable_qtlog_context_manager(pytester, use_context_manager): """ Test qtlog.disabled() context manager. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = CRITICAL """) @@ -124,7 +124,7 @@ def test_disable_qtlog_context_manager(testdir, use_context_manager): else: code = "if 1:" - testdir.makepyfile( + pytester.makepyfile( """ from pytestqt.qt_compat import qt_api def test_1(qtlog): @@ -132,25 +132,25 @@ def test_1(qtlog): qt_api.qCritical('message') """.format(code=code) ) - res = testdir.inline_run() + res = pytester.inline_run() passed = 1 if use_context_manager else 0 res.assertoutcome(passed=passed, failed=int(not passed)) @pytest.mark.parametrize("use_mark", [True, False]) -def test_disable_qtlog_mark(testdir, use_mark): +def test_disable_qtlog_mark(pytester, use_mark): """ Test mark which disables logging capture for a test. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = CRITICAL """) mark = "@pytest.mark.no_qt_log" if use_mark else "" - testdir.makepyfile( + pytester.makepyfile( """ from pytestqt.qt_compat import qt_api import pytest @@ -159,25 +159,25 @@ def test_1(): qt_api.qCritical('message') """.format(mark=mark) ) - res = testdir.inline_run() + res = pytester.inline_run() passed = 1 if use_mark else 0 res.assertoutcome(passed=passed, failed=int(not passed)) -def test_logging_formatting(testdir): +def test_logging_formatting(pytester): """ Test custom formatting for logging messages. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile(""" + pytester.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}") + res = pytester.runpytest(f"--qt-log-format={f}") today = "{:%Y-%m-%d}".format(datetime.datetime.now()) res.stdout.fnmatch_lines( [ @@ -190,19 +190,19 @@ def test_types(): @pytest.mark.parametrize( "level, expect_passes", [("DEBUG", 1), ("WARNING", 2), ("CRITICAL", 3), ("NO", 4)] ) -def test_logging_fails_tests(testdir, level, expect_passes): +def test_logging_fails_tests(pytester, level, expect_passes): """ Test qt_log_level_fail ini option. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini( + pytester.makeini( """ [pytest] qt_log_level_fail = {level} """.format(level=level) ) - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api def test_1(): qt_api.qDebug('this is a DEBUG message') @@ -213,7 +213,7 @@ def test_3(): def test_4(): assert 1 """) - res = testdir.runpytest() + res = pytester.runpytest() lines = [] if level != "NO": lines.extend( @@ -228,41 +228,41 @@ def test_4(): res.stdout.fnmatch_lines(lines) -def test_logging_fails_tests_mark(testdir): +def test_logging_fails_tests_mark(pytester): """ Test mark overrides what's configured in the ini file. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = CRITICAL """) - testdir.makepyfile(""" + pytester.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 = pytester.inline_run() res.assertoutcome(failed=1) -def test_logging_fails_ignore(testdir): +def test_logging_fails_ignore(pytester): """ Test qt_log_ignore config option. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = CRITICAL qt_log_ignore = WM_DESTROY.*sent WM_PAINT not handled """) - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api import pytest @@ -277,7 +277,7 @@ def test4(): qt_api.qCritical('WM_PAINT not handled') qt_api.qCritical('another critical message') """) - res = testdir.runpytest() + res = pytester.runpytest() lines = [ # test1 fails because it has emitted a CRITICAL message and that message # does not match any regex in qt_log_ignore @@ -303,18 +303,18 @@ def test4(): @pytest.mark.parametrize("message", ["match-global", "match-mark"]) @pytest.mark.parametrize("marker_args", ["'match-mark', extend=True", "'match-mark'"]) -def test_logging_mark_with_extend(testdir, message, marker_args): +def test_logging_mark_with_extend(pytester, message, marker_args): """ Test qt_log_ignore mark with extend=True. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = CRITICAL qt_log_ignore = match-global """) - testdir.makepyfile( + pytester.makepyfile( """ from pytestqt.qt_compat import qt_api import pytest @@ -324,25 +324,25 @@ def test1(): qt_api.qCritical('{message}') """.format(message=message, marker_args=marker_args) ) - res = testdir.inline_run() + res = pytester.inline_run() res.assertoutcome(passed=1, failed=0) @pytest.mark.parametrize( "message, error_expected", [("match-global", True), ("match-mark", False)] ) -def test_logging_mark_without_extend(testdir, message, error_expected): +def test_logging_mark_without_extend(pytester, message, error_expected): """ Test qt_log_ignore mark with extend=False. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = CRITICAL qt_log_ignore = match-global """) - testdir.makepyfile( + pytester.makepyfile( """ from pytestqt.qt_compat import qt_api import pytest @@ -352,7 +352,7 @@ def test1(): qt_api.qCritical('{message}') """.format(message=message) ) - res = testdir.inline_run() + res = pytester.inline_run() if error_expected: res.assertoutcome(passed=0, failed=1) @@ -360,20 +360,20 @@ def test1(): res.assertoutcome(passed=1, failed=0) -def test_logging_mark_with_invalid_argument(testdir): +def test_logging_mark_with_invalid_argument(pytester): """ Test qt_log_ignore mark with invalid keyword argument. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest @pytest.mark.qt_log_ignore('match-mark', does_not_exist=True) def test1(): pass """) - res = testdir.runpytest() + res = pytester.runpytest() lines = [ "*= ERRORS =*", "*_ ERROR at setup of test1 _*", @@ -386,17 +386,17 @@ def test1(): @pytest.mark.parametrize("apply_mark", [True, False]) -def test_logging_fails_ignore_mark_multiple(testdir, apply_mark): +def test_logging_fails_ignore_mark_multiple(pytester, apply_mark): """ Make sure qt_log_ignore mark supports multiple arguments. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ if apply_mark: mark = '@pytest.mark.qt_log_ignore("WM_DESTROY", "WM_PAINT")' else: mark = "" - testdir.makepyfile( + pytester.makepyfile( """ from pytestqt.qt_compat import qt_api import pytest @@ -406,23 +406,23 @@ def test1(): qt_api.qCritical('WM_PAINT was sent') """.format(mark=mark) ) - res = testdir.inline_run() + res = pytester.inline_run() passed = 1 if apply_mark else 0 res.assertoutcome(passed=passed, failed=int(not passed)) -def test_lineno_failure(testdir): +def test_lineno_failure(pytester): """ Test that tests when failing because log messages were emitted report the correct line number. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makeini(""" + pytester.makeini(""" [pytest] qt_log_level_fail = WARNING """) - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api def test_foo(): assert foo() == 10 @@ -430,7 +430,7 @@ def foo(): qt_api.qWarning('this is a WARNING message') return 10 """) - res = testdir.runpytest() + res = pytester.runpytest() if qt_api.is_pyqt: res.stdout.fnmatch_lines( [ @@ -448,7 +448,7 @@ def foo(): ) -def test_context_none(testdir): +def test_context_none(pytester): """ Sometimes PyQt will emit a context with some/all attributes set as None instead of appropriate file, function and line number. @@ -456,9 +456,9 @@ def test_context_none(testdir): Test that when this happens the plugin doesn't break, and it filters out the context information. - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api def test_foo(request): @@ -468,20 +468,20 @@ def test_foo(request): context, "WARNING message") assert 0 """) - res = testdir.runpytest() + res = pytester.runpytest() assert "*None:None:0:*" not in str(res.stdout) res.stdout.fnmatch_lines(["QtWarningMsg: WARNING message"]) -def test_logging_broken_makereport(testdir): +def test_logging_broken_makereport(pytester): """ Make sure logging's makereport hookwrapper doesn't hide exceptions. See https://github.com/pytest-dev/pytest-qt/issues/98 - :type testdir: _pytest.pytester.TmpTestdir + :type pytester: pytest.Pytester """ - testdir.makepyfile( + pytester.makepyfile( conftest=""" import pytest @@ -492,9 +492,9 @@ def pytest_runtest_makereport(call): yield """ ) - p = testdir.makepyfile(""" + p = pytester.makepyfile(""" def test_foo(): pass """) - res = testdir.runpytest_subprocess(p) + res = pytester.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 f4dfa94..4c9084b 100644 --- a/tests/test_modeltest.py +++ b/tests/test_modeltest.py @@ -315,8 +315,8 @@ 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(""" +def test_qt_tester_valid(pytester): + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api from pytestqt import modeltest @@ -327,17 +327,17 @@ def test_ok(qtmodeltester): model = qt_api.QtGui.QStandardItemModel() qtmodeltester.check(model) """) - res = testdir.inline_run() + res = pytester.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(""" +def test_qt_tester_invalid(pytester): + pytester.makeini(""" [pytest] qt_log_level_fail = NO """) - testdir.makepyfile(""" + pytester.makepyfile(""" from pytestqt.qt_compat import qt_api from pytestqt import modeltest @@ -365,7 +365,7 @@ def test_ok(qtmodeltester): model = Model() qtmodeltester.check(model) """) - res = testdir.runpytest() + res = pytester.runpytest() res.stdout.fnmatch_lines( [ "*__ test_ok __*", diff --git a/tests/test_qtest_proxies.py b/tests/test_qtest_proxies.py index 23492fc..81860c7 100644 --- a/tests/test_qtest_proxies.py +++ b/tests/test_qtest_proxies.py @@ -31,12 +31,12 @@ def test_expected_qtest_proxies(qtbot, expected_method): @pytest.mark.skipif(qt_api.is_pyside, reason="PyQt test only") -def test_keyToAscii_not_available_on_pyqt(testdir): +def test_keyToAscii_not_available_on_pyqt(pytester): """ Test that qtbot.keyToAscii() is not available on PyQt5 and calling the method raises a NotImplementedError. """ - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -46,5 +46,5 @@ def test_foo(qtbot): with pytest.raises(NotImplementedError): qtbot.keyToAscii(qt_api.QtCore.Qt.Key.Key_Escape) """) - result = testdir.runpytest() + result = pytester.runpytest() result.stdout.fnmatch_lines(["*= 1 passed in *"]) diff --git a/tests/test_wait_signal.py b/tests/test_wait_signal.py index 07613e8..eafa7b4 100644 --- a/tests/test_wait_signal.py +++ b/tests/test_wait_signal.py @@ -148,14 +148,14 @@ def test_zero_timeout(qtbot, timer, delayed, signaller): @pytest.mark.parametrize( "configval, raises", [("false", False), ("true", True), (None, True)] ) -def test_raising(qtbot, testdir, configval, raises): +def test_raising(qtbot, pytester, configval, raises): if configval is not None: - testdir.makeini(f""" + pytester.makeini(f""" [pytest] qt_default_raising = {configval} """) - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -169,7 +169,7 @@ def test_foo(qtbot): pass """) - res = testdir.runpytest() + res = pytester.runpytest() if raises: res.stdout.fnmatch_lines(["*1 failed*"]) @@ -177,13 +177,13 @@ def test_foo(qtbot): res.stdout.fnmatch_lines(["*1 passed*"]) -def test_raising_by_default_overridden(qtbot, testdir): - testdir.makeini(""" +def test_raising_by_default_overridden(qtbot, pytester): + pytester.makeini(""" [pytest] qt_default_raising = false """) - testdir.makepyfile(""" + pytester.makepyfile(""" import pytest from pytestqt.qt_compat import qt_api @@ -197,7 +197,7 @@ def test_foo(qtbot): with qtbot.waitSignal(signal, raising=True, timeout=10) as blocker: pass """) - res = testdir.runpytest() + res = pytester.runpytest() res.stdout.fnmatch_lines(["*1 failed*"])