Skip to content

wxGUI: Add pytest tests running under Xvfb - #8267

Open
echoix wants to merge 11 commits into
OSGeo:mainfrom
echoix:claude/wxgui-pytest
Open

echoix wants to merge 11 commits into
OSGeo:mainfrom
echoix:claude/wxgui-pytest

Conversation

@echoix

@echoix echoix commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

First basic GUI test on pytest. It tests that the interface creates the dialog correctly.

Starting as a draft to evaluate the approach first.

My goal here is to set up the plumbing correctly to have GUI tests, and Python-only non-GUI tests (but for code in the gui subfolder) to be handled correctly.

Description

  • Add pytest fixtures for the GUI in gui/wxpython/conftest.py: gui_session, a GRASS session mirrored to os.environ with the GUI directory on sys.path (GUI modules are unloaded afterwards), and wx_app, a wx.App whose windows are destroyed at the end of the session.
  • Add a test which imports every installed GUI module, and a test which builds the g.region dialog from its interface and checks the generated command.
  • Tests using wx_app are marked needs_wx_app automatically. They run in their own pytest step in the pytest and CMake workflows on Ubuntu (under xvfb-run), and on macOS and Windows; the other pytest runs exclude them. GUI tests without the wx.App run with the other tests.
  • Without a display, the wx_app tests are skipped locally and fail in CI, so that the step can't pass without running them.
  • In the pytest workflow, install the latest wxPython wheel for Ubuntu from its GitHub release (4.3.2, tracked by Renovate), Xvfb, and the libraries the wheel needs.
  • In the CMake workflow, which already installs wxPython from the Ubuntu packages (4.2.1), install Xvfb, so the GUI tests also run with that older wxPython.
  • Document the fixtures and how to run the GUI tests in doc/development/testing.md, including running them separately from the other tests, since some global settings changed by the GUI modules stay for the rest of the process.

Motivation and context

The GUI has no tests run in CI. The import test is cheap and catches broken imports.

The tests creating the wx.App run in a separate process because one wx.App lives for the whole process, and its GTK threads make fork() in other tests warn about possible deadlocks (seen in the pygrass grid tests). The display and the GUI imports also stay out of the other tests.

xvfb-run is used directly, as in the wxPython CI, instead of pytest-xvfb, which depends on the unmaintained PyVirtualDisplay.

How has this been tested?

Locally on Ubuntu 24.04 with Python 3.13, wxPython 4.3.2 and a CMake build of GRASS:

  • The new CI step under xvfb-run: 222 passed, also with -n 2.
  • The solo and parallel test runs with the CI arguments collect none of the wx_app tests; a GUI test without the wx.App runs in the parallel run.
  • Without a display: skipped (exit code 0), or failed with CI=true.
  • All needs_solo_run tests of the repository in one process, including the GUI tests: passed.

Possible follow-up: the dialog test could use GUI(show=False), so that no window shows up on the macOS and Windows runners.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the
    pre-defined prefixes
  • My code follows the code style
    of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

The tests and CI changes were written with the help of Claude Code.

Suggested squash commit message
wxGUI: Add pytest tests running under Xvfb

Add pytest fixtures for a GRASS session and a wx.App, a test which
imports every installed GUI module, and a test of the dialog generated
from a tool interface. Without a display, the tests are skipped, or fail
in CI.

Tests using the wx.App are marked needs_wx_app automatically and run in
their own pytest step in the pytest and CMake workflows on Ubuntu, and
on macOS and Windows, because the wx.App lives for the whole process
and its threads affect other tests, such as those using fork(). The
other runs exclude them. On Ubuntu, the step runs under xvfb-run, with
the wxPython wheel from its GitHub release in the pytest workflow and
the Ubuntu wxPython package in the CMake workflow.

Document the fixtures and how to run the GUI tests.

The tests and CI changes were written with the help of Claude Code.

Add fixtures for a GRASS session and a wx.App, a test which imports
every installed GUI module, and a test of the dialog generated from a
tool interface. The tests skip when wxPython is not installed or no
display is available.

In the pytest workflow, install Xvfb with pytest-xvfb, the libraries
wxPython needs (listed in apt_wxgui.txt, so that other workflows using
apt.txt keep the smaller list), and the latest wxPython wheel for Ubuntu
from its GitHub release. The wheel is installed with uv, because its
metadata lack the local version in the file name, which pip rejects.

The tests were written with the help of Claude Code.
@github-actions github-actions Bot added GUI wxGUI related CI Continuous integration Python Related code is in Python tests Related to Test Suite labels Nov 25, 2026
Claude added 6 commits November 25, 2026 22:07
The wx.App fixture teardown called wx.App.ProcessIdle, which does not
exist in wxPython (only wx.EventLoopBase has it). Remove it with the
wx.SafeYield call: the destroyed windows are deleted by the wx cleanup
at exit.

Tests using the wx.App are marked needs_wx_app automatically and run in
a separate pytest step on Ubuntu, macOS and Windows. With the wx.App in
the process, GTK threads are running and fork() in other tests warns
about possible deadlocks; the Xvfb display and GUI imports also stay
out of the other tests. The other runs exclude these tests and disable
pytest-xvfb. GUI tests without the wx.App still run with the others,
in parallel unless marked needs_solo_run.

Split the long wxPython release URL line for yamllint.

Written with the help of Claude Code.
Run only the step with the tests which need the wx.App under xvfb-run,
as the wxPython CI does, instead of using the pytest-xvfb plugin, which
depends on the unmaintained PyVirtualDisplay. The other test runs no
longer need to disable the plugin.

Written with the help of Claude Code.
The step with the tests which need the wx.App runs only these tests, so
skipping them all for a missing display would leave the step passing.
Fail instead when the CI variable is set, as on GitHub Actions. Locally,
the tests are still skipped without a display.

Written with the help of Claude Code.
Describe the gui_session and wx_app fixtures, the needs_wx_app marker,
and how to run the GUI tests with a virtual display.

Written with the help of Claude Code.
The parallel run selected tests only by needs_solo_run, so a test using
the wx.App without that marker ran there instead of in its own step.

Written with the help of Claude Code.
The wx.App and global settings changed by the GUI modules, such as
raise on error set by the animation tool, stay for the rest of the
process.

Written with the help of Claude Code.
@github-actions github-actions Bot added windows Microsoft Windows specific macOS macOS specific docs markdown Related to markdown, markdown files labels Nov 25, 2026
echoix and others added 2 commits November 26, 2026 19:42
The tests marked with needs_wx_app are excluded from the shared pytest
argument files, so the CMake workflow needs its own step to run them.
The workflow already installs wxPython from apt; apt_wxgui.txt adds
xvfb for the virtual display.

Written with the help of Claude Code.
@echoix
echoix marked this pull request as ready for review November 27, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous integration docs GUI wxGUI related macOS macOS specific markdown Related to markdown, markdown files Python Related code is in Python tests Related to Test Suite windows Microsoft Windows specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants