Skip to content

test: commit tests/conftest.py (headless defaults, no GUI popups) - #123

Merged
petercorke merged 3 commits into
mainfrom
test/commit-conftest
Oct 3, 2026
Merged

petercorke merged 3 commits into
mainfrom
test/commit-conftest

Conversation

@petercorke

@petercorke petercorke commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of the untracked-file cleanup in #45. tests/conftest.py has been sitting untracked, so it applied on dev machines but never in CI. It:

  • sets MPLBACKEND=Agg, QT_QPA_PLATFORM=offscreen and MVTB_TEST_MODE=True (each only if not already set);
  • for every test, replaces cv2.namedWindow / imshow / waitKey / destroyWindow / destroyAllWindows and plt.show with no-ops, so display code paths run without opening windows.

Local only. The file does nothing when CI is set (GitHub Actions sets CI=true) or MVTB_TEST_REAL_GUI=1, so CI keeps exercising the real OpenCV HighGUI calls (namedWindow / imshow / waitKey / destroyWindow) on each OS and OpenCV version, exactly as today, and a developer can opt in to real windows locally. The stubs and the environment defaults only apply to local runs. (Stubbing everywhere would have dropped CI's only coverage of the real window path; idisp's readback tests intercept cv2.imshow and never check a native window.)

CI currently sets only MPLBACKEND=Agg and runs with real OpenCV window calls. Committing this makes dev and CI test conditions the same, and stops windows popping up when the suite is run on a desktop (it did when I ran the suite without it on a Mac: windows appeared three separate times across the runs that did not use it).

Verification

Same working tree, OpenCV 5.0 (the pip opencv-python-headless wheel, which on macOS still reports a Cocoa GUI, so windows can open in the --noconftest run), with and without the file (--noconftest): 946 passed, 95 skipped, identical skip list, 0 failures in both. So it changes no test outcome; it only suppresses GUI side effects.

Which tests open windows (A/B-tested on macOS, OpenCV 5.0 with a Cocoa GUI). A recorder plugin that stubs the OpenCV window functions and plt.show and logs the caller found 42 tests that call a GUI function; 36 of them call OpenCV window functions, all in two files. Running each of those files alone, unstubbed, opened real windows both times (observed by eye, not detected programmatically):

File Tests calling window functions Unstubbed run
tests/base/test_io.py 31 (imshow, namedWindow, waitKey, destroyWindow, plt.show) windows appeared (~5 s)
tests/base/test_idisp_display_readback.py 6 (namedWindow, waitKey) windows appeared (~3 s)

The other 6 GUI-calling tests only call plt.show, which is a no-op with the Agg backend. With the recorder (same stubbing as this conftest, plus logging) no window appeared and the suite result was unchanged (946 passed, 95 skipped).

Two caveats found while checking, neither caused by this PR:

  • My first with/without comparison used a clean checkout for the "without" side and showed 2 extra skips. Those were tests/test_image_sources.py:98 and :182 (bridge-l.zip not available): the 122 MB zip is untracked and git-ignored, so it exists in a dev working tree but not in CI. Those two tests are therefore always skipped in CI. Related to the mvtb-data / large-file plan.
  • The MVTB_TEST_MODE default only matters for the tests/RVC notebooks, which already have their own tracked tests/RVC/conftest.py and a Makefile setting.

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally
  • CI green (CI is the first place this file will run)

🤖 Generated with Claude Code

The file has been sitting untracked, so it applied on dev machines but never
in CI. It sets MPLBACKEND=Agg, QT_QPA_PLATFORM=offscreen and
MVTB_TEST_MODE=True (only if unset) and, for every test, replaces the OpenCV
window functions and plt.show with no-ops so display code can be exercised
without windows opening.

Pass/skip results are identical with and without it (946 passed, 95 skipped,
same skip list, headless OpenCV 5.0, same working tree).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 11 complexity · 0 duplication

Metric Results
Complexity 11
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

petercorke and others added 2 commits October 3, 2026 17:59
The OpenCV HighGUI calls (namedWindow/imshow/waitKey/destroyWindow) are the
only coverage of the real window path on each OS and OpenCV version, and CI
runs them for real today (pytest-xvfb on Linux, desktop sessions on
macOS/Windows runners). Stubbing them everywhere would drop that.

conftest.py now does nothing when CI is set (GitHub Actions sets CI=true) or
MVTB_TEST_REAL_GUI=1; otherwise behaviour is as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke merged commit 43b113e into main Oct 3, 2026
35 checks passed
@petercorke
petercorke deleted the test/commit-conftest branch October 3, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant