-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactor tests to use create_autospec() for more robust mocking #11876
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: master
Are you sure you want to change the base?
Refactor tests to use create_autospec() for more robust mocking #11876
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #11876 +/- ##
==========================================
- Coverage 98.75% 98.72% -0.03%
==========================================
Files 127 127
Lines 44171 44255 +84
Branches 2342 2343 +1
==========================================
+ Hits 43619 43690 +71
- Misses 392 404 +12
- Partials 160 161 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #11876 will not alter performanceComparing Summary
Footnotes |
| req = make_client_request( | ||
| "post", URL("http://python.org/"), data="foo", compress="deflate", loop=loop | ||
| ) | ||
| with mock.patch("aiohttp.client_reqrep.StreamWriter") as m_writer: |
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.
In these cases, it's the mock.patch() that's missing it:
| with mock.patch("aiohttp.client_reqrep.StreamWriter") as m_writer: | |
| with mock.patch("aiohttp.client_reqrep.StreamWriter", autospec=True, spec_set=True) as m_writer: |
The other lines can then likely be removed entirely.
What do these changes do?
Refactors test files to use
create_autospec()instead of andmock.AsyncMock()for more robust mocking. This ensures mocks match the actual interface of the objects being mocked.Are there changes in behavior for the user?
No, just improving tests
Is it a substantial burden for the maintainers to support this?
No. This change actually reduces maintenance burden by making tests more robust. in case the interface changes the mock would fail instead of silently passing with incorrect mocks.
Related issue number
N/A - This is based on the suggestion from @Dreamsorcerer in #10910 (comment)
Checklist
CONTRIBUTORS.txtCHANGES/folder<issue_or_pr_num>.<type>.rst(e.g.588.bugfix.rst)number after creating the PR (use
.misctype for this change)