tests: Do not patch builtins.open directly#1436
Merged
vojtechtrefny merged 1 commit intostoraged-project:mainfrom Nov 20, 2025
Merged
tests: Do not patch builtins.open directly#1436vojtechtrefny merged 1 commit intostoraged-project:mainfrom
vojtechtrefny merged 1 commit intostoraged-project:mainfrom
Conversation
This causes coverity to fail, because it internally uses open() which we just mocked.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideTests updated to mock the module-level open in blivet.devicelibs.lvm instead of patching builtins.open, isolating file operations within the lvm code and avoiding interference with Coverity’s own file usage. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tests/unit_tests/devicelibs_test/lvm_test.py:20` </location>
<code_context>
def test_lvm_autoactivation(self):
localconf = "global { event_activation = 0 }"
with patch("blivet.devicelibs.lvm.open", mock_open(read_data=localconf)):
# already disabled
with self.assertRaises(RuntimeError):
lvm.disable_lvm_autoactivation()
localconf = ""
with patch("blivet.devicelibs.lvm.open", mock_open(read_data=localconf)) as m:
lvm.disable_lvm_autoactivation()
m.assert_called_with("/etc/lvm/lvmlocal.conf", "a")
handle = m()
handle.write.assert_called_once_with("global { event_activation = 0 }")
localconf = "test\ntest"
with patch("blivet.devicelibs.lvm.open", mock_open(read_data=localconf)) as m:
# not disabled
with self.assertRaises(RuntimeError):
lvm.reenable_lvm_autoactivation()
localconf = "# global { event_activation = 0 }"
with patch("blivet.devicelibs.lvm.open", mock_open(read_data=localconf)) as m:
# not disabled
with self.assertRaises(RuntimeError):
lvm.reenable_lvm_autoactivation()
localconf = "test\nglobal { event_activation = 0 }"
with patch("blivet.devicelibs.lvm.open", mock_open(read_data=localconf)) as m:
lvm.reenable_lvm_autoactivation()
m.assert_called_with("/etc/lvm/lvmlocal.conf", "w+")
handle = m()
handle.write.assert_called_once_with("test\n")
</code_context>
<issue_to_address>
**issue (code-quality):** Extract duplicate code into method ([`extract-duplicate-method`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/extract-duplicate-method/))
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
This causes coverity to fail, because it internally uses open() which we just mocked.
Summary by Sourcery
Update LVM unit tests to patch the open function in the module under test instead of mocking builtins.open to avoid interfering with external tools like Coverity
Bug Fixes:
Tests: