From 95e2672d5510378b7e86f730d1ad22310bb06797 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 6 Nov 2025 11:10:09 -0800 Subject: [PATCH] Add more tests --- tests/test_validation_error_context.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_validation_error_context.py b/tests/test_validation_error_context.py index a03286a9e..a22f436b9 100644 --- a/tests/test_validation_error_context.py +++ b/tests/test_validation_error_context.py @@ -2,6 +2,7 @@ from fastapi import FastAPI, Request, WebSocket from fastapi.exceptions import ( RequestValidationError, ResponseValidationError, + WebSocketException, WebSocketRequestValidationError, ) from fastapi.testclient import TestClient @@ -93,3 +94,23 @@ def test_websocket_validation_error_includes_endpoint_context(): error_str = str(captured_exception.exception) assert "websocket_endpoint" in error_str assert "/ws/" in error_str + + +def test_validation_error_with_only_path(): + """Test formatting when only endpoint_path is available (lines 175-176).""" + errors = [{"type": "missing", "loc": ("body", "name"), "msg": "Field required"}] + exc = RequestValidationError(errors, endpoint_ctx={"path": "GET /api/test"}) + error_str = str(exc) + assert "Endpoint: GET /api/test" in error_str + assert 'File "' not in error_str + + +def test_validation_error_with_no_context(): + """Test formatting when no context is available (line 177).""" + errors = [{"type": "missing", "loc": ("body", "name"), "msg": "Field required"}] + exc = RequestValidationError(errors, endpoint_ctx={}) + error_str = str(exc) + assert "1 validation error:" in error_str + assert "Endpoint" not in error_str + assert 'File "' not in error_str +