Skip to content

Conversation

@soheil-star01
Copy link

What do these changes do?

Refactors test files to use create_autospec() instead of and mock.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

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)
    • if you don't have an issue number, change it to the pull request
      number after creating the PR (use .misc type for this change)

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Dec 29, 2025
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

❌ Patch coverage is 88.46154% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.72%. Comparing base (963ca76) to head (41a9e88).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tests/test_client_session.py 75.00% 10 Missing ⚠️
tests/test_http_writer.py 66.66% 2 Missing ⚠️
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     
Flag Coverage Δ
CI-GHA 98.58% <88.46%> (-0.03%) ⬇️
OS-Linux 98.32% <88.46%> (-0.03%) ⬇️
OS-Windows 96.66% <88.46%> (-0.03%) ⬇️
OS-macOS 97.54% <88.46%> (-0.04%) ⬇️
Py-3.10.11 97.08% <88.46%> (-0.03%) ⬇️
Py-3.10.19 97.58% <88.46%> (-0.03%) ⬇️
Py-3.11.14 97.79% <88.46%> (-0.03%) ⬇️
Py-3.11.9 97.29% <88.46%> (-0.03%) ⬇️
Py-3.12.10 97.39% <88.46%> (-0.03%) ⬇️
Py-3.12.12 97.88% <88.46%> (-0.03%) ⬇️
Py-3.13.11 98.14% <88.46%> (-0.03%) ⬇️
Py-3.14.2 98.15% <88.46%> (-0.04%) ⬇️
Py-3.14.2t 97.22% <88.46%> (-0.04%) ⬇️
Py-pypy3.11.13-7.3.20 97.39% <88.46%> (-0.03%) ⬇️
VM-macos 97.54% <88.46%> (-0.04%) ⬇️
VM-ubuntu 98.32% <88.46%> (-0.03%) ⬇️
VM-windows 96.66% <88.46%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 29, 2025

CodSpeed Performance Report

Merging #11876 will not alter performance

Comparing soheil-star01:test-refactor-use-autospec (41a9e88) with master (4379717)1

Summary

✅ 59 untouched

Footnotes

  1. No successful run was found on master (46aabe9) during the generation of this report, so 4379717 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@soheil-star01 soheil-star01 marked this pull request as draft December 29, 2025 14:00
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:
Copy link
Member

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:

Suggested change
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.

@Dreamsorcerer Dreamsorcerer added the backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot label Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants