# Testing your Python integration

`watchtower15.testing` holds fakes for your tests. They hold only placeholder credentials, never sleep, and never reach a host.

```python
from watchtower15.testing import FakeClient, MockTransport

def test_reports_critical_servers() -> None:
    client = FakeClient()
    client.queue("public.servers.list", MockTransport.envelope([{"uuid": "u1", "name": "web-1"}]))
    report_critical_servers(client)
    client.assert_called("public.servers.list", times=1)
```

-   **`FakeClient`** is a `Client`, and **`AsyncFakeClient`** an `AsyncClient`. Ingest pushes are answered with an accepted envelope; any other operation is answered from `queue(operation_id, answer)`, else the call raises naming the operation. `calls()`, `assert_called(operation_id, where=None, times=None)`, `assert_not_called()`, `pushed_points()`, `pushed_lines()`, `assert_pushed(kind=None)` and `assert_nothing_pushed()` read what happened.
-   **`MockTransport`** is the transport behind them (`AsyncMockTransport` for the async one): `append()`, and the builders `json()`, `problem()`, `envelope()`, `metrics_accepted()` and `logs_accepted()`. Recorded requests keep the `Authorization` masked and the body decoded.
-   **`FakeAggregator`** records `increments()` and `gauges()` (`assert_incremented()`, `assert_gauge_set()`, `assert_nothing_recorded()`); its `flush()` is always final, into its `FakeClient`, so the open minute reaches `client.pushed_points()` with no waiting. **`FakeClock`** is a clock you `advance()`.

A failed assertion raises `AssertionError`, which pytest and `unittest` both report with the recorded calls in the message. The integrations accept `fake=True` to build these fakes for you: see each framework’s page.

## A pytest fixture

```python
import pytest
from watchtower15.testing import FakeAggregator, FakeClient

@pytest.fixture
def wt15() -> FakeClient:
    return FakeClient()

@pytest.fixture
def metrics(wt15: FakeClient) -> FakeAggregator:
    return FakeAggregator(wt15)
```

Pass `wt15` and `metrics` to the code under test in place of the real ones, then assert: `metrics.assert_incremented("orders.created", times=1)`.

Source: https://developer.watchtower15.com/sdks/python/testing/
