fix: mock remaining OpenCV GUI calls in tests to prevent guiReceiver error - #297
Open
Sthitadhi1 wants to merge 1 commit into
Open
fix: mock remaining OpenCV GUI calls in tests to prevent guiReceiver error#297Sthitadhi1 wants to merge 1 commit into
Sthitadhi1 wants to merge 1 commit into
Conversation
…error Adds mocks for cv2.namedWindow, cv2.moveWindow, and cv2.getWindowProperty in setup_mocker_patches(), which were previously unmocked and caused cv2.error: NULL guiReceiver (please create a window) when running pytest or pre-commit hooks in headless environments (no display server). Fixes Udayraj123#230 Signed-off-by: Sthitadhi Maity <maitysthitadhi@gmail.com>
PR Summary by QodoFix headless test failures by mocking remaining OpenCV GUI calls
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTo customize comments, go to the Qodo configuration screen, or learn more in the docs. |
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.
Problem
When running
pytestorpre-commithooks in headless environments (e.g., CI runners, containers, or environments without an active display server), the test suite fails with:Root Cause
InteractionUtils.show()andis_window_available()insrc/utils/interaction.pyinvokecv2.namedWindow(),cv2.moveWindow(), andcv2.getWindowProperty(). Previously,setup_mocker_patches()insrc/tests/utils.pyonly mockedcv2.imshow,cv2.destroyAllWindows, andcv2.waitKey. The three unmocked OpenCV GUI functions attempted real GUI window operations during testing, which fail in headless environments without a display backend.Fix
Updated
setup_mocker_patches(mocker)insrc/tests/utils.pyto add mocks for the remaining OpenCV GUI calls:cv2.namedWindow-> returnsNonecv2.moveWindow-> returnsNonecv2.getWindowProperty-> returns1(simulates window visibility)No production code in
src/utils/interaction.pywas altered, preserving actual display runtime behavior for end users.Testing Notes
pytestandpre-committhatcv2.error: NULL guiReceiver (please create a window)is completely eliminated.\vs/) and are unrelated to this OpenCV GUI mocking fix.Fixes #230