-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: Use pytest-mock in tests #847
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #847 +/- ##
==========================================
- Coverage 85.12% 85.06% -0.07%
==========================================
Files 65 65
Lines 5931 5931
==========================================
- Hits 5049 5045 -4
- Misses 882 886 +4 ☔ View full report in Codecov by Sentry. |
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.
This is looking great.
All the repetition of various mocker.patch.object(AnkiHubClient, "some_method")
usages make me think a custom fixture to assist with patching the client in various ways might be useful after this first wave of monkey patch refactoring.
Sounds good. I'm curious how this would look like. |
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.
This looks great! I think #849 should be merged into this first and then I think this is ready to go. It looks like there's an minor import difference that needs resolving before merging to main
.
* chore: Replaces usages of monkeypatch in test_client.py * Attempt to use mocker and reset os.remove (#850) * Attempt to use mocker and reset os.remove * Use mocker.resetall to reset all mocks * Use stop (reset is just for the mock call values) * Fix types: use mocker.stop on remove_mock --------- Co-authored-by: Trey Hunner <[email protected]>
* Replace some monkeypatch uses with pytest-mock * Use mocker everywhere in integration tests Replace all uses of unittest.mock, monkeypatch fixture, and the custom mock_function fixture with the mocker fixture from pytest-mock. * Use mocker for mock_function fixture * Use non-string type annotations for Mock * Prefer mocker.patch over mocker.patch.object * Apply suggestions from code review Co-authored-by: Jakub Fidler <[email protected]> * Fix variable name typos (mesaage -> message) * Remove unused mock_function fixture --------- Co-authored-by: Jakub Fidler <[email protected]>
Replace usages of
monkeypatch
(+unittest.mock
) or our custommock_function
fixture withpytest-mock
. This simplifies the test code.Related issues
Proposed changes
pytest-mock
to requirementsmonkeypatch
withmocker.patch
mock_function
fixture withmocker.patch
unittest.Mock()
withmocker.stub()
ormocker.Mock()