Skip to content

Commit 1552409

Browse files
authored
Log context of openapi validation crash (#6448)
1 parent ce39fa3 commit 1552409

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

tests/openapi/helpers/helpers.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import json
2+
import time
23
from logging import warning
34
from typing import Any, Dict, List
45
import jsonschema
56
import requests
67
import warnings
8+
from schemathesis.exceptions import CheckFailed
79
from schemathesis.models import APIOperation
810
from schemathesis.specs.openapi.references import ConvertingResolver
911
from schemathesis.specs.openapi.schemas import OpenApi30
@@ -81,14 +83,35 @@ def request_with_validation(
8183
warnings.warn(f"Delete call for {api} missing wait=true param, adding it")
8284
query_params["wait"] = "true"
8385

86+
start_time = time.time()
8487
response = action(
8588
url=get_api_string(QDRANT_HOST, api, path_params),
8689
params=query_params,
8790
json=body,
8891
headers=qdrant_host_headers()
8992
)
90-
91-
operation.validate_response(response)
93+
duration = time.time() - start_time
94+
try:
95+
operation.validate_response(response)
96+
except CheckFailed as ex:
97+
status = response.status_code
98+
headers_str = "\n".join(f"{k}: {v}" for k, v in response.headers.items())
99+
body_text = response.text.strip()
100+
msg = (
101+
f"Failed validation {ex} for response:\n"
102+
f"Status: {status}\n"
103+
f"Headers:\n{headers_str}\n"
104+
f"Body (decoded text):\n{body_text if body_text else '[Empty Body]'}\n"
105+
f"Duration: {duration:.2f} seconds\n"
106+
f"Request was:\n"
107+
f"Method: {method}\n"
108+
f"URL: {get_api_string(QDRANT_HOST, api, path_params)}\n"
109+
f"Query params: {query_params}\n"
110+
f"Headers: {qdrant_host_headers()}\n"
111+
f"Body: {body}\n"
112+
)
113+
warnings.warn(msg)
114+
raise
92115

93116
return response
94117

0 commit comments

Comments
 (0)