From fdc53efc3522f1d2b55dc6881f23d3f7361fc332 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Fri, 28 Jul 2023 11:44:54 +0300 Subject: [PATCH] tests: Test our own custom QApplication By default, `pytest-qt` initializes the default QApplication class that PySide offers. Dangerzone, however, defines its own QApplication subclass. Create a `qapp_cls` fixture that will force `pytest-qt` to use this subclass. For more info, see: https://pytest-qt.readthedocs.io/en/latest/qapplication.html#testing-custom-qapplications --- dangerzone/gui/__init__.py | 4 ++-- tests/conftest.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/conftest.py diff --git a/dangerzone/gui/__init__.py b/dangerzone/gui/__init__.py index 08fa44e..f0249ac 100644 --- a/dangerzone/gui/__init__.py +++ b/dangerzone/gui/__init__.py @@ -37,8 +37,8 @@ class Application(QtWidgets.QApplication): document_selected = QtCore.Signal(list) application_activated = QtCore.Signal() - def __init__(self) -> None: - super(Application, self).__init__() + def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: + super(Application, self).__init__(*args, **kwargs) self.setQuitOnLastWindowClosed(False) with open(get_resource_path("dangerzone.css"), "r") as f: style = f.read() diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..84fcc1e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,12 @@ +import typing + +import pytest + +from dangerzone.gui import Application + + +# Use this fixture to make `pytest-qt` invoke our custom QApplication. +# See https://pytest-qt.readthedocs.io/en/latest/qapplication.html#testing-custom-qapplications +@pytest.fixture(scope="session") +def qapp_cls() -> typing.Type[Application]: + return Application