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
This commit is contained in:
Alex Pyrgiotis 2023-07-28 11:44:54 +03:00
parent 24ba914cc8
commit fdc53efc35
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
2 changed files with 14 additions and 2 deletions

View file

@ -37,8 +37,8 @@ class Application(QtWidgets.QApplication):
document_selected = QtCore.Signal(list) document_selected = QtCore.Signal(list)
application_activated = QtCore.Signal() application_activated = QtCore.Signal()
def __init__(self) -> None: def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
super(Application, self).__init__() super(Application, self).__init__(*args, **kwargs)
self.setQuitOnLastWindowClosed(False) self.setQuitOnLastWindowClosed(False)
with open(get_resource_path("dangerzone.css"), "r") as f: with open(get_resource_path("dangerzone.css"), "r") as f:
style = f.read() style = f.read()

12
tests/conftest.py Normal file
View file

@ -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