Testing¶
The test suite runs without MIMIC-IV access, cloud credentials, or network access. Real data is replaced by synthetic trajectories and a fake BigQuery client.
pytest
Tests live in tests/, one file per feature area, such as
test_medication_actions.py or test_bigquery_pipeline.py.
Conventions¶
Synthetic data first. Use
make_synthetic_dataset()with a fixedseedfor any test that needs a dataset. Passinclude_medication_metadata=Truefor two-column medication actions.Fake the BigQuery client, not BigQuery.
tests/test_bigquery_pipeline.pydefinesFakeGuardedClient, which returns prepared DataFrames by matching the SQL it receives. Pipeline tests use it to exercise the real loader end to end. Use it rather than mockinggoogle.cloud.bigquery.Skip on missing extras. Tests that need
d3rlpystart withpytest.importorskip("d3rlpy"), so a plain.[dev]install still passes.Cohorts larger than one. Bugs that only appear across trajectories, such as mismatched metadata, need at least two patients. Prefer small multi-patient fixtures.
Assert behavior and error messages. Use
pytest.raises(..., match=...)so a test fails if the wrong error is raised.
Test families¶
Area |
Files |
|---|---|
Data model and CSV path |
|
Itemid maps and presets |
|
BigQuery |
|
Actions |
|
Rewards |
|
Policy, export, provenance |
|
Synthetic data and examples |
|
Public API documentation |
|
test_public_docs.py holds the list of supported public objects. It checks
that each is exported in __all__ and has a descriptive docstring, and the
documentation tests use the same list.
Documentation tests¶
The site has its own tests in docs/tests/, which build the site strictly and
inspect the HTML. They need the docs extra and are not part of the default
pytest run:
.venv-docs/bin/python -m pytest docs/tests