Skip to content

Commit

Permalink
Fix Segmentation fault when using PySide2 and running pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
5yutan5 committed Dec 5, 2022
1 parent f828f5e commit 5600608
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"pytest",
"pytestqt",
"pyupgrade",
"qapp",
"qdarktheme",
"QLCD",
"qproperty",
Expand Down
25 changes: 5 additions & 20 deletions tests/test_qdarktheme_with_qt.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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())

0 comments on commit 5600608

Please sign in to comment.