test: commit tests/conftest.py (headless defaults, no GUI popups) - #123
Merged
Merged
Conversation
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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 11 |
| Duplication | 0 |
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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of the untracked-file cleanup in #45.
tests/conftest.pyhas been sitting untracked, so it applied on dev machines but never in CI. It:MPLBACKEND=Agg,QT_QPA_PLATFORM=offscreenandMVTB_TEST_MODE=True(each only if not already set);cv2.namedWindow/imshow/waitKey/destroyWindow/destroyAllWindowsandplt.showwith no-ops, so display code paths run without opening windows.Local only. The file does nothing when
CIis set (GitHub Actions setsCI=true) orMVTB_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 interceptcv2.imshowand never check a native window.)CI currently sets only
MPLBACKEND=Aggand 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-headlesswheel, which on macOS still reports a Cocoa GUI, so windows can open in the--noconftestrun), 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.showand 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):tests/base/test_io.pyimshow,namedWindow,waitKey,destroyWindow,plt.show)tests/base/test_idisp_display_readback.pynamedWindow,waitKey)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:
tests/test_image_sources.py:98and: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.MVTB_TEST_MODEdefault only matters for thetests/RVCnotebooks, which already have their own trackedtests/RVC/conftest.pyand a Makefile setting.Checklist
🤖 Generated with Claude Code