Skip to content

fix(tests): pin httpcore so a sys.modules patch cannot split it (#4439) - #4447

Merged
vybe merged 1 commit into
devfrom
fix/4439-httpcore-pollution
Nov 10, 2026
Merged

vybe merged 1 commit into
devfrom
fix/4439-httpcore-pollution

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Fixes #4439

Journey Impact: none: test-harness isolation only; no product code changes

Problem

dev has been red since e6d36a94, on test_ent926_runtime_turn_scope::test_an_unreachable_platform_is_no_answer with httpcore.ConnectError: All connection attempts failed. It failed on 3 of 4 dev runs and passes when run alone.

The cause: httpx 0.28 imports httpcore lazily and caches its exception map (httpx._transports.default.HTTPCORE_EXC_MAP) on the first request. When httpcore is first imported inside a patch.dict(sys.modules, ...) block, it is dropped when the block exits (about 30 unit files use that pattern). The next import creates a second httpcore module. Its ConnectError matches nothing in the cached map, so it gets past every except httpx.HTTPError raw. Whether this happens depends on which tests share an xdist worker.

Fix

tests/unit/conftest.py imports httpcore before any test can snapshot sys.modules, so every snapshot already holds it and no restore removes it. (tests/unit/pytest.ini makes the unit suite its own rootdir, so the root conftest isn't loaded there.)

Validation

  • test_4439_httpcore_pinned.py primes the map inside a sys.modules patch, then fails a connect after the patch exits. With the pin commented out it is red (2 failed, with the same httpcore.ConnectError as dev). With the pin it is green.
  • test_1484, test_2107, test_1759 (all use patch.dict("sys.modules")) followed by test_4439 and test_ent926 on one process: 148 passed.
  • tests/lint_sys_modules.py: OK, no new violations.

Not covered here: the other one-off dev failure, test_ent1094_marketplace_release.py::TestBootCheck::test_a_signal_during_cleanup_still_destroys_the_droplet[2] (JSONDecodeError at 8fe1ec77), is a different shape and is not addressed by this PR.

🤖 Generated with Claude Code

httpx 0.28 imports httpcore lazily and caches its exception map on the
first request. A `patch.dict(sys.modules, ...)` block that first imported
httpcore drops it on exit; the re-import is a second module whose
ConnectError matches nothing in the cached map, so it escapes every
`except httpx.HTTPError` raw. That is why
test_ent926_runtime_turn_scope::test_an_unreachable_platform_is_no_answer
failed on 3 of 4 dev runs (httpcore.ConnectError) and passed alone.

The unit conftest now imports httpcore before any test can snapshot
sys.modules. test_4439_httpcore_pinned.py reproduces the escape (red with
the pin removed, green with it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@vybe vybe 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.

merge-train 2026-11-10: dev-red fix for #4439, merged alone ahead of the train.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants