-
Notifications
You must be signed in to change notification settings - Fork 45
LCORE-175: Use patches to not modify global config value in test_feedback #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe unit tests for the Changes
Estimated code review effort1 (~2 minutes) Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/unit/app/endpoints/test_feedback.py (1)
107-107
: Consider extending the patching approach to other tests for consistency.While the main objective of this PR has been achieved, there are still other tests in this file that directly modify global configuration values (lines 107 and 138). For better test isolation and consistency, consider applying the same patching approach to these tests as well.
For example,
test_store_feedback
could use:with patch("app.endpoints.feedback.configuration.user_data_collection_configuration.feedback_storage", "fake-path"):And
test_feedback_status
could use:with patch("app.endpoints.feedback.configuration.user_data_collection_configuration.feedback_enabled", True):Also applies to: 138-138
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/unit/app/endpoints/test_feedback.py
(2 hunks)
🧬 Code Graph Analysis (1)
tests/unit/app/endpoints/test_feedback.py (1)
src/app/endpoints/feedback.py (1)
is_feedback_enabled
(41-47)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/unit/app/endpoints/test_feedback.py (1)
src/app/endpoints/feedback.py (1)
is_feedback_enabled
(41-47)
🔇 Additional comments (3)
tests/unit/app/endpoints/test_feedback.py (3)
3-3
: LGTM: Import addition is correct and necessary.The import of
patch
fromunittest.mock
is properly added to support the refactored test methods.
20-24
: Excellent refactoring: Improved test isolation with proper patching.The use of
patch
context manager instead of direct global config modification is a significant improvement. This ensures the original configuration is automatically restored after the test, preventing side effects on other tests.
29-33
: LGTM: Consistent implementation with the enabled test.The patching approach is correctly applied here as well, maintaining consistency with the
test_is_feedback_enabled
function while testing the opposite scenario.
/retest |
@matysek anything we should worry about ^? It seems to be related with the new Python image |
I think the error was in my other PR too, but was fixed by retest after I pushed some changes there. Can you try to hit the retest? It seems I don't have that option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error in the CI seems unrelated:
Error: creating build container: initializing source docker://registry.access.redhat.com/ubi9/python-312-minimal:latest: reading manifest latest in registry.access.redhat.com/ubi9/python-312-minimal: received unexpected HTTP status: 500 Internal Server Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, fat fingered the approve. I think we should use pytest instead of the built-in module for consistency
@@ -1,5 +1,7 @@ | |||
"""Unit tests for the /feedback REST API endpoint.""" | |||
|
|||
from unittest.mock import patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use pytest
) | ||
|
||
|
||
def test_is_feedback_enabled(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_is_feedback_enabled(mocker):
...
with mocker.patch(....
assert is_feedback_enabled() is True, "Feedback should be enabled" | ||
|
||
|
||
def test_is_feedback_disabled(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, let's use mocker instead of built-in mock since we already use pytest
/retest |
Description
Use patches in test_is_feedback_enabled and test_is_feedback_disabled to not modify global config value.
Type of change
Related Tickets & Documents
https://issues.redhat.com/browse/LCORE-175
Checklist before requesting a review
Testing
Summary by CodeRabbit