The Python SDK ships a dedicatedDocumentation Index
Fetch the complete documentation index at: https://docs.trulayer.ai/llms.txt
Use this file to discover all available pages before exploring further.
trulayer.testing module with an in-memory sender and a fluent assertion chain. No API key is required, no network calls are made, and the helpers work under pytest, unittest, or any runner that treats AssertionError as a failure.
Install
Write your first test
API
create_test_client(**overrides)
Returns a (client, sender) tuple. The client is a fully functional TruLayerClient wired to an in-memory LocalBatchSender. Pass keyword overrides (sample_rate, redact, project) to exercise specific client behavior:
assert_sender(sender)
Entry point for the fluent assertion chain. Each method returns self so assertions chain naturally.
| Method | Behaviour |
|---|---|
.has_trace(trace_id=None) | Asserts the sender captured at least one trace, or the trace with the given ID. |
.span_count(n) | Asserts the total span count across all captured traces. |
.has_span_named(name) | Asserts at least one span with the given name is present; error message lists observed span names. |
Replay captured traces
LocalBatchSender.flush_to_file(path) serializes every captured trace to a JSONL file — one JSON object per line. Combined with TRULAYER_MODE=replay, this enables golden-file regression tests and reproducing production traces locally.
warnings.warn — the helper follows the SDK’s never-throws contract so a single corrupt line in a fixture never takes down an entire test run.
Running captures via environment variables
For integration tests that spin up a full app, set the mode variables on the process before loading your code.trulayer.init() wires them up automatically:
TRULAYER_MODE=replay implies local — replayed traces never escape to the live API, because they were produced by a previous capture and would double-count.
See also
- Failure behavior — how the SDK handles ingest outages and how to opt in to block mode.
- Python SDK reference — full signatures for
create_test_client,assert_sender, andLocalBatchSender.