From 56006088710e7140f61ae41265bcb600c0eb4faf Mon Sep 17 00:00:00 2001 From: 5yutan5 <63651161+5yutan5@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:23:44 +0900 Subject: [PATCH] Fix `Segmentation fault` when using PySide2 and running pytest --- .vscode/settings.json | 1 + tests/test_qdarktheme_with_qt.py | 25 +++++-------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b7427ec0..860379a2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -46,6 +46,7 @@ "pytest", "pytestqt", "pyupgrade", + "qapp", "qdarktheme", "QLCD", "qproperty", diff --git a/tests/test_qdarktheme_with_qt.py b/tests/test_qdarktheme_with_qt.py index a416bc9b..52170b12 100644 --- a/tests/test_qdarktheme_with_qt.py +++ b/tests/test_qdarktheme_with_qt.py @@ -1,9 +1,8 @@ """Tests for the main program with Qt.""" -import sys - import pytest import qdarktheme +from qdarktheme.qtpy.QtWidgets import QApplication @pytest.mark.parametrize( @@ -34,25 +33,11 @@ def test_load_palette(theme, custom_colors) -> None: qdarktheme.load_palette(theme, custom_colors) -def test_apply_stylesheet_to_qt_app() -> None: +def test_apply_stylesheet_to_qt_app(qapp: QApplication) -> None: """Verify that the function `load_stylesheet()` runs without error.""" - from qdarktheme.qtpy.QtCore import Qt - from qdarktheme.qtpy.QtWidgets import QApplication - - app = QApplication.instance() if QApplication.instance() else QApplication(sys.argv) - if hasattr(Qt.ApplicationAttribute, "AA_UseHighDpiPixmaps"): - app.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) # type: ignore - - app.setStyleSheet(qdarktheme.load_stylesheet()) + qapp.setStyleSheet(qdarktheme.load_stylesheet()) -def test_apply_palette_to_qt_app() -> None: +def test_apply_palette_to_qt_app(qapp: QApplication) -> None: """Verify that the function `load_palette()` runs without error.""" - from qdarktheme.qtpy.QtCore import Qt - from qdarktheme.qtpy.QtWidgets import QApplication - - app = QApplication.instance() if QApplication.instance() else QApplication(sys.argv) - if hasattr(Qt.ApplicationAttribute, "AA_UseHighDpiPixmaps"): - app.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) # type: ignore - - app.setPalette(qdarktheme.load_palette()) + qapp.setPalette(qdarktheme.load_palette())