Repository navigation
fix(tests): pin httpcore so a sys.modules patch cannot split it (#4439) - #4447
Merged
Merged
Conversation
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]>
This was referenced Nov 10, 2026
AndriiPasternak31
added a commit
that referenced
this pull request
Nov 10, 2026
Brings #4447 (httpcore pinned against a sys.modules split). No conflicts.
AndriiPasternak31
added a commit
that referenced
this pull request
Nov 10, 2026
…asternak31/issue-4281-schedule-run-tier Brings dev's #4447 through the guardrail branch. No conflicts.
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4439
Journey Impact: none: test-harness isolation only; no product code changes
Problem
devhas been red sincee6d36a94, ontest_ent926_runtime_turn_scope::test_an_unreachable_platform_is_no_answerwithhttpcore.ConnectError: All connection attempts failed. It failed on 3 of 4devruns 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 apatch.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. ItsConnectErrormatches nothing in the cached map, so it gets past everyexcept httpx.HTTPErrorraw. Whether this happens depends on which tests share an xdist worker.Fix
tests/unit/conftest.pyimports httpcore before any test can snapshotsys.modules, so every snapshot already holds it and no restore removes it. (tests/unit/pytest.inimakes the unit suite its own rootdir, so the root conftest isn't loaded there.)Validation
test_4439_httpcore_pinned.pyprimes the map inside asys.modulespatch, then fails a connect after the patch exits. With the pin commented out it is red (2 failed, with the samehttpcore.ConnectErrorasdev). With the pin it is green.test_1484,test_2107,test_1759(all usepatch.dict("sys.modules")) followed bytest_4439andtest_ent926on one process: 148 passed.tests/lint_sys_modules.py: OK, no new violations.Not covered here: the other one-off
devfailure,test_ent1094_marketplace_release.py::TestBootCheck::test_a_signal_during_cleanup_still_destroys_the_droplet[2](JSONDecodeError at8fe1ec77), is a different shape and is not addressed by this PR.🤖 Generated with Claude Code