Add initial support for running tests offscreen

Makes

    QT_QPA_PLATFORM=offscreen pytest

pass.

See #4914
This commit is contained in:
Florian Bruhin 2025-03-12 14:41:50 +01:00 committed by Chad Kouse
parent eac4b333ea
commit bba6e57e70
No known key found for this signature in database
GPG Key ID: 2BBC602A2578C7A2
5 changed files with 29 additions and 5 deletions

View File

@ -50,7 +50,7 @@ pytest-qt==4.4.0
pytest-repeat==0.9.3
pytest-rerunfailures==15.0
pytest-xdist==3.6.1
pytest-xvfb==3.0.0
pytest-xvfb==3.1.1
PyVirtualDisplay==3.0
requests==2.32.3
requests-file==2.1.0

View File

@ -19,6 +19,7 @@ markers =
not_frozen: Tests which can't be run if sys.frozen is True.
not_flatpak: Tests which can't be run if running with Flatpak.
no_xvfb: Tests which can't be run with Xvfb.
no_offscreen: Tests which can't be run with the offscreen platform plugin.
frozen: Tests which can only be run if sys.frozen is True.
integration: Tests which test a bigger portion of code
end2end: End to end tests which run qutebrowser as subprocess
@ -82,7 +83,10 @@ qt_log_ignore =
# Qt 6.9 Beta 1-3 with Xvfb
^Backend texture is not a Vulkan texture\.$
# With offscreen platform plugin
^This plugin does not support (raise|propagateSizeHints)\(\)$
^This plugin does not support (raise\(\)|propagateSizeHints\(\)|createPlatformVulkanInstance|grabbing the keyboard)$
^QRhiGles2: Failed to create (temporary )?context$
^QVulkanInstance: Failed to initialize Vulkan$
^Unable to detect GPU vendor\.$
xfail_strict = true
filterwarnings =
error

View File

@ -104,6 +104,10 @@ def _apply_platform_markers(config, item):
pytest.mark.skipif,
testutils.ON_CI,
"Skipped on CI."),
('no_offscreen',
pytest.mark.skipif,
testutils.offscreen_plugin_enabled(),
"Skipped with offscreen platform plugin."),
('unicode_locale',
pytest.mark.skipif,
sys.getfilesystemencoding() == 'ascii',
@ -317,10 +321,19 @@ def pytest_report_header(config):
@pytest.fixture(scope='session', autouse=True)
def check_display(request):
if utils.is_linux and not os.environ.get('DISPLAY', ''):
if (
utils.is_linux
and not os.environ.get("DISPLAY", "")
and not testutils.offscreen_plugin_enabled()
):
raise RuntimeError("No display and no Xvfb available!")
def pytest_xvfb_disable() -> bool:
"""Disable Xvfb if the offscreen plugin is in use."""
return testutils.offscreen_plugin_enabled()
@pytest.fixture(autouse=True)
def set_backend(monkeypatch, request):
"""Make sure the backend global is set."""

View File

@ -1551,7 +1551,7 @@ Feature: Tab management
And I run :tab-take 0/1
Then the error "Can't take tabs when using windows as tabs" should be shown
@windows_skip
@windows_skip @no_offscreen
Scenario: Close the last tab of a window when taken by another window
Given I have a fresh instance
When I open data/numbers/1.txt
@ -1633,7 +1633,7 @@ Feature: Tab management
And I run :tab-give 0
Then the error "Can't give tabs when using windows as tabs" should be shown
@windows_skip
@windows_skip @no_offscreen
Scenario: Close the last tab of a window when given to another window
Given I have a fresh instance
When I open data/numbers/1.txt

View File

@ -323,6 +323,12 @@ SOFTWARE_RENDERING_FLAG = "--disable-gpu"
SOFTWARE_RENDERING_ARGS = ["-s", "qt.force_software_rendering", "chromium"]
def offscreen_plugin_enabled() -> bool:
"""Check whether offscreen rendering is enabled."""
# FIXME allow configuring via custom CLI flag?
return os.environ["QT_QPA_PLATFORM"] == "offscreen"
def use_software_rendering() -> bool:
"""Check whether to enforce software rendering for tests."""
if not _has_qtwebengine():
@ -333,6 +339,7 @@ def use_software_rendering() -> bool:
# https://github.com/qutebrowser/qutebrowser/issues/8444#issuecomment-2569554046
# not on CI, but unknown how to tell apart affected / unaffected systems
versions.webengine == utils.VersionNumber(6, 9)
or offscreen_plugin_enabled()
)