Files

32 lines
1.3 KiB
Python

"""Keep one QApplication alive, matching the desktop application's lifecycle."""
import os
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
os.environ.setdefault("QTWEBENGINE_DISABLE_SANDBOX", "1")
os.environ.setdefault("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-gpu --no-sandbox --log-level=3")
import pytest
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QFontDatabase
from PySide6.QtCore import QCoreApplication, QEvent
@pytest.fixture(scope="session", autouse=True)
def qt_application():
app = QApplication.instance() or QApplication([])
# Windows' offscreen plugin has no system font database. Register the same
# font used by PDF headers so the test exercises real glyph embedding.
if os.name == "nt" and not QFontDatabase.families():
QFontDatabase.addApplicationFont(os.path.join(os.environ.get("WINDIR", "C:/Windows"), "Fonts", "msyh.ttc"))
yield app
app.processEvents()
@pytest.fixture(autouse=True)
def release_closed_widgets(qt_application):
yield
# processEvents alone does not flush DeferredDelete without app.exec().
# Release closed WebEngine pages before the next rendering regression.
QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete)
qt_application.processEvents()