Skip to content

Switch test suite from aioresponses to aiointercept#347

Merged
agners merged 5 commits into
mainfrom
switch-to-aiointercept
Jun 11, 2026
Merged

Switch test suite from aioresponses to aiointercept#347
agners merged 5 commits into
mainfrom
switch-to-aiointercept

Conversation

@bdraco

@bdraco bdraco commented Jun 8, 2026

Copy link
Copy Markdown
Member

Proposed Changes

Switch the test suite from aioresponses to aiointercept.

aioresponses mocks by calling the ClientResponse constructor directly, but that constructor is not public; the aiohttp docs are explicit that users never construct ClientResponse, they only get it from API calls. By replicating that signature aioresponses ties itself to an aiohttp internal that changes as needed, so it breaks on nearly every minor bump. The latest case is aiohttp 3.14, where ClientResponse gained a required stream_writer argument and every mocked request now raises a TypeError. aiohttp maintainers have said they will not keep patching aioresponses for this, and recommend migrating; see aio-libs/aiohttp#12815 and the discussion at aio-libs/discussions/45.

aiointercept routes requests through a real aiohttp test server instead of monkey patching internals, so it does not depend on private signatures and keeps working across aiohttp releases. The mock_external_urls option keeps the SUPERVISOR_URL host intercepted, so the call sites are unchanged apart from the rename. The client side request timeout is not visible through a real round trip, so it is captured with a small fixture and asserted through a shared helper. The aiohttp pin is left as is so dependabot can bump it in #344.

Related Issues

Unblocks #344, works around aio-libs/aiohttp#12815

aioresponses 0.7.8 breaks under aiohttp 3.14; ClientResponse now requires
a stream_writer argument so every mocked request raised a TypeError.
aiointercept routes requests through a real aiohttp test server instead of
monkey patching internals, so it keeps working across aiohttp releases.

The mock_external_urls option keeps the SUPERVISOR_URL host intercepted, so
the existing call sites need no changes. The client side request timeout is
not visible through a real round trip, so it is captured with a fixture and
asserted via a shared helper. Also bumps the pinned aiohttp to 3.14.1.
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.56%. Comparing base (9508b0a) to head (3dd3cd4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #347   +/-   ##
=======================================
  Coverage   99.56%   99.56%           
=======================================
  Files          34       34           
  Lines        1381     1381           
=======================================
  Hits         1375     1375           
  Misses          6        6           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bdraco bdraco added the maintenance Generic maintenance tasks. label Jun 8, 2026
@bdraco

bdraco commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@esphbot review

@esphbot

esphbot commented Jun 8, 2026

Copy link
Copy Markdown

Previous review — superseded by a newer review below.

@esphbot esphbot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found.

@esphbot

esphbot commented Jun 8, 2026

Copy link
Copy Markdown

Previous review — superseded by a newer review below.

@esphbot esphbot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found.

@bdraco bdraco marked this pull request as ready for review June 8, 2026 16:45
@esphbot

esphbot commented Jun 8, 2026

Copy link
Copy Markdown

PR Review — Switch test suite from aioresponses to aiointercept

Clean, test-only migration from aioresponses to aiointercept. Merge-ready.

  • Mechanical aioresponsesaiointercept rename across all test modules; call sites preserved via mock_external_urls=True.
  • request_timeouts fixture correctly captures the client-side timeout by monkeypatching ClientSession.request (auto-reverted), since timeout is no longer observable through a real round trip; assert_request_timeout helper includes a membership guard for legible failures.
  • type RequestTimeouts statement is valid — confirmed requires-python = >=3.13.0.
  • location set→list changes make JSON ordering deterministic; DownloadBackupOptions(location=None) query change (?location= → ``) matches real client behavior (if options and options.location: omits the param — verified in `backups.py:168`).
  • aiohttp pinned to 3.14.1; coverage unchanged at 99.56%.


Checklist

  • No hardcoded secrets
  • Python version compatibility (type statement requires 3.12+; requires-python is >=3.13.0)
  • Test assertions reflect real observable behavior
  • Test isolation (monkeypatch auto-reverts)
  • Clear failure messages on assertion paths

Automated review by Kōan (Claude) HEAD=b9ade2a 37s

@esphbot esphbot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found.

@MartinHjelmare MartinHjelmare left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and sounds good. @agners do you agree?

@agners agners left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aiointercept seems to be a step towards integration tests. Personally, I like unit tests to be just unit tests with as little system dependencies and not doing any I/O etc.

But relying on testing dependencies which hold back the main dependency upgrades is arguably worse. With aiointercept being the recommended unit test suite for aiohttp client requests, sure let's go with it!

@agners agners merged commit f843362 into main Jun 11, 2026
23 of 25 checks passed
@agners agners deleted the switch-to-aiointercept branch June 11, 2026 21:30
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

maintenance Generic maintenance tasks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants