Skip to content

Commit d624e73

Browse files
committed
test: replace if/else branch with single assert to satisfy 100% branch coverage
The prior if/else on sys.version_info created a branch where only one side executes per CI job (each job pins a single Python version), so coverage's --cov-branch --cov-fail-under=100 flags the always-taken branch as partial on every job in the matrix (all failed on this PR's last CI run). Collapsing to a single assert against a version-gated tuple keeps the exact same behavioral pinning (PARSE_ERROR only below 3.14, either code on 3.14+) without introducing an untestable branch. Verified locally on Python 3.10 (lowest supported): full suite passes (5444 passed, 9 skipped, 1 xfailed), coverage report shows 100.00% total including this file, ruff check and ruff format --check clean. <sub>AI Disclosure: https://gist.github.com/maxisbey/6123d132484e4c533eab519a2800693d</sub>
1 parent 1956ff6 commit d624e73

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

tests/server/test_streamable_http_modern.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,8 @@ async def test_modern_post_with_deeply_nested_body_is_rejected_not_a_crash() ->
10301030
async with _asgi_client(_x_mcp_server()) as http:
10311031
response = await http.post("/mcp", content=body, headers={"content-type": "application/json"})
10321032
assert response.status_code == 400
1033-
if sys.version_info >= (3, 14):
1034-
assert response.json()["error"]["code"] in (PARSE_ERROR, INVALID_REQUEST)
1035-
else:
1036-
assert response.json()["error"]["code"] == PARSE_ERROR
1033+
allowed_codes = (PARSE_ERROR, INVALID_REQUEST) if sys.version_info >= (3, 14) else (PARSE_ERROR,)
1034+
assert response.json()["error"]["code"] in allowed_codes
10371035

10381036

10391037
async def test_modern_post_recursion_error_during_parse_is_parse_error(monkeypatch: pytest.MonkeyPatch) -> None:

0 commit comments

Comments
 (0)