test_copy_build_request() — anthropic-sdk-python Function Reference
Architecture documentation for the test_copy_build_request() function in test_client.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 702b2cf9_feca_3e68_addc_69dd90b45e8f["test_copy_build_request()"] 9bf4cfe0_e3b0_70de_25ac_2113c8918900["TestAsyncAnthropic"] 702b2cf9_feca_3e68_addc_69dd90b45e8f -->|defined in| 9bf4cfe0_e3b0_70de_25ac_2113c8918900 e22034d2_309c_9ab1_a7a5_3ad92238df9e["test_copy_build_request()"] e22034d2_309c_9ab1_a7a5_3ad92238df9e -->|calls| 702b2cf9_feca_3e68_addc_69dd90b45e8f e22034d2_309c_9ab1_a7a5_3ad92238df9e["test_copy_build_request()"] 702b2cf9_feca_3e68_addc_69dd90b45e8f -->|calls| e22034d2_309c_9ab1_a7a5_3ad92238df9e style 702b2cf9_feca_3e68_addc_69dd90b45e8f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_client.py lines 1228–1288
def test_copy_build_request(self, async_client: AsyncAnthropic) -> None:
options = FinalRequestOptions(method="get", url="/foo")
def build_request(options: FinalRequestOptions) -> None:
client_copy = async_client.copy()
client_copy._build_request(options)
# ensure that the machinery is warmed up before tracing starts.
build_request(options)
gc.collect()
tracemalloc.start(1000)
snapshot_before = tracemalloc.take_snapshot()
ITERATIONS = 10
for _ in range(ITERATIONS):
build_request(options)
gc.collect()
snapshot_after = tracemalloc.take_snapshot()
tracemalloc.stop()
def add_leak(leaks: list[tracemalloc.StatisticDiff], diff: tracemalloc.StatisticDiff) -> None:
if diff.count == 0:
# Avoid false positives by considering only leaks (i.e. allocations that persist).
return
if diff.count % ITERATIONS != 0:
# Avoid false positives by considering only leaks that appear per iteration.
return
for frame in diff.traceback:
if any(
frame.filename.endswith(fragment)
for fragment in [
# to_raw_response_wrapper leaks through the @functools.wraps() decorator.
#
# removing the decorator fixes the leak for reasons we don't understand.
"anthropic/_legacy_response.py",
"anthropic/_response.py",
# pydantic.BaseModel.model_dump || pydantic.BaseModel.dict leak memory for some reason.
"anthropic/_compat.py",
# Standard library leaks we don't care about.
"/logging/__init__.py",
]
):
return
leaks.append(diff)
leaks: list[tracemalloc.StatisticDiff] = []
for diff in snapshot_after.compare_to(snapshot_before, "traceback"):
add_leak(leaks, diff)
if leaks:
for leak in leaks:
print("MEMORY LEAK:", leak)
for frame in leak.traceback:
print(frame)
raise AssertionError()
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does test_copy_build_request() do?
test_copy_build_request() is a function in the anthropic-sdk-python codebase, defined in tests/test_client.py.
Where is test_copy_build_request() defined?
test_copy_build_request() is defined in tests/test_client.py at line 1228.
What does test_copy_build_request() call?
test_copy_build_request() calls 1 function(s): test_copy_build_request.
What calls test_copy_build_request()?
test_copy_build_request() is called by 1 function(s): test_copy_build_request.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free