mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* test(unit): reset module state only when a test changed it The proxy conftest deep-copied every snapshotted litellm attribute before each test, and the copy of litellm.model_cost alone was a median 0.12 s for each of 56,031 proxy tests on the runner. The reset now copies an attribute back only when it no longer equals the snapshot. The enterprise and MCP server conftests reloaded litellm before every test, 3.27 s and 0.21 s per test. They now use the same reset. * test(unit): remove six flaky tests They failed on main without a code change behind them between 2026-11-05 and 2026-11-14: the vector store hook SDK fallback, the concurrent user config TPM count, three Prometheus metrics server port tests and the OpenCode list cost billing test. * ci: run four heavy unit shards on 16-core runners and keep two smoke jobs off pull requests proxy-feature-endpoints, proxy-endpoints, root and llms-providers ran 1.9 to 2.2 times faster with 8 workers on a 16-core runner in a benchmark run. windows-sdk and proxy-build-from-pip still run on pushes to main and manual runs. proxy-build-from-pip installs a published release and never runs the pull request's code. * test: move 109 tests that start a process or open a socket into tests/integration tests/unit is in-process by its own rules, and these tests spawn a Python interpreter, a shell or a local TCP or HTTP server. They took 921 s of unit shard time per run, 396 s of it in the MCP client transport tests. Each one now lives in a *_real_io.py file under the integration directory for its domain and runs with that directory's group. The tests themselves are unchanged apart from one repository-root path in the CLI test. * test(unit): copy back only the dict entries a test changed A test module that registers models at import leaves litellm.model_cost four entries larger than the snapshot before every test in its directory, so the reset still deep-copied the whole price map for each of them. It now rebuilds a changed dict from the live entries that still match and copies only the rest. * ci(smoke): keep the two jobs that skip on pull requests out of the smoke gate A skipped job passing the gate is what test_unit_passed_gate guards against, so the gate goes back to requiring success from every job it needs and windows-sdk and proxy-build-from-pip stop being part of it. They still run and report on pushes to main and manual runs.
57 lines
3.6 KiB
Markdown
57 lines
3.6 KiB
Markdown
# tests/integration
|
|
|
|
Real proxy, Postgres, Redis, scripted upstream. `README.md` has shards and CI wiring
|
|
|
|
## What good looks like
|
|
|
|
The root example is from here. The spend row lands async: poll, never sleep
|
|
|
|
```python
|
|
rows = eventually(
|
|
lambda: read_rows('SELECT spend FROM "LiteLLM_SpendLogs" WHERE request_id=%s', (body["id"],)),
|
|
lambda values: len(values) == 1,
|
|
seconds=70,
|
|
)
|
|
assert float(rows[0]["spend"]) == pytest.approx(10 * 0.001 + 5 * 0.0001 + 7 * 0.002 + 4 * 0.002)
|
|
```
|
|
|
|
`sleep(3)` fails on a slow runner and taxes every fast one. Assert the outbound body in the upstream
|
|
handler. A leaked field is invisible from the response. `monkeypatch.setenv` is fine. Patching our own
|
|
function in a full stack is not
|
|
|
|
## Where it goes
|
|
|
|
By the domain a user would name: `pricing`, `spend`, `routing`, `mcp`. A file only needs to live in a
|
|
directory that a `GROUPS` entry in `run.py` selects. There is no manifest and no `covers` marker on new
|
|
tests. A product bug the test exposes is `pytest.skip("BUG: <symptom>")` at the top of the body, not a
|
|
fix in the test and not a deletion. Needs no network, proxy, DB or Redis: `tests/unit`
|
|
|
|
A test that starts its own process or opens its own socket but needs no proxy also lives here, in a
|
|
`*_real_io.py` file next to the domain it covers, because `tests/unit` is in-process. It asks for none of
|
|
the gateway fixtures, so it runs as plain pytest inside its group
|
|
|
|
GitHub Actions integration groups run every file here except the OCI and sandbox tests, which no CI runs, and
|
|
the files in `GITHUB_FILES` in `run.py`. `test-integration.yml` runs the same groups through the same
|
|
`run_integration.sh` on GitHub Actions, on main every three hours from 8am to 8pm Pacific Monday to Saturday,
|
|
and on a pull request when someone adds the `run-ci` label. These jobs do not run every pull request, so a new file here
|
|
first runs on main after its PR merges, or earlier if the PR gets `run-ci`. Wanting a file to run before merge
|
|
is no reason to change CI, and a new
|
|
dedicated workflow for it is the same mistake as a shared shard. Write the file, leave `GITHUB_FILES` and
|
|
every workflow alone, and tell the user it first runs on main. `GITHUB_FILES` is only for a file that
|
|
needs what GitHub Actions groups cannot give it, like the images `image-scan.yml` builds. `test_roi_observed.py` previously needed a dedicated plain pytest
|
|
job and now has no CI owner. It is listed explicitly in the coverage allowlist. Add a file to `GITHUB_FILES` only when needed,
|
|
together with its dedicated job, and list a new dedicated GitHub workflow with the directory it owns in
|
|
`DEDICATED_INTEGRATION_WORKFLOWS` in `.github/scripts/assert_ci_coverage.py`. The `ci-coverage` check
|
|
fails a file here that another workflow selects unless that workflow owns its path in
|
|
`DEDICATED_INTEGRATION_WORKFLOWS` (#46780).
|
|
|
|
## Fixtures that boot a proxy
|
|
|
|
Scope them to the module or class, or pin a session one to a single worker with an `xdist_group` mark
|
|
as `_llm_gateway` in `mcp/test_mcp_llm_endpoints.py` does, and request them as arguments, never through
|
|
`request.getfixturevalue`. The harness puts tests that request the same set of module or class fixtures
|
|
on one xdist worker, so the proxy they share boots there once and stops when that worker moves to another
|
|
file. A test that requests one more of those fixtures than its neighbors gets its own group and can boot
|
|
the proxy again on another worker, so keep that set the same across the tests that share a proxy. An
|
|
unpinned session fixture boots a copy on every worker that runs one of its tests and keeps them all until
|
|
the node ends, and those copies ran GitHub Actions integration-extensions nodes out of memory
|