Airflow Test Writer
Write tests for Airflow backend API endpoints.
Usage
/af-test <endpoint file path or description>
Test Location
Tests mirror the source tree:
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/foo.py
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_foo.py
Conventions
Structure
- One test class per endpoint, named
Test<EndpointFunction> (e.g. TestGetPartitionedDagRuns)
- All test methods inside the class, with descriptive names
- Auth tests in every class:
test_should_response_401, test_should_response_403
- Use
pytestmark = pytest.mark.db_test at module level
- Use
@pytest.fixture(autouse=True) for cleanup
Parametrize over separate methods
- Prefer one parametrized test over multiple methods with similar setup
- Use
@pytest.mark.parametrize with ids for all variants
- Vary inputs (counts, booleans, enums) and derive expected values in the test body
- Keep assertions generic enough to work across all parameter combinations
Example: instead of test_pending, test_fulfilled, test_partial, write one test_should_response_200 parametrized on (num_assets, received_count, fulfilled).
Fixtures and helpers
- Use
dag_maker fixture to create DAGs, call dag_maker.sync_dagbag_to_db() after
- Use
session fixture for direct DB operations (add, flush, commit)
- Use
test_client for authenticated requests, unauthenticated_test_client / unauthorized_test_client for auth tests
- Use
assert_queries_count to verify query efficiency where existing tests do
- Cleanup helpers from
tests_common.test_utils.db: clear_db_dags, clear_db_serialized_dags, clear_db_apdr, clear_db_pakl, etc.
Instructions
Read the endpoint code to understand the route, parameters, response model, and dependencies.
Read 1-2 existing test files in the same directory to match the local style. Use the closest neighbor (e.g. test_assets.py for asset-related endpoints).
Write the test file with:
- Auth tests (401, 403) for each endpoint class
- 404 for missing resources
- One parametrized 200 test covering: happy path, edge cases (empty/partial data), and relevant filter/flag combinations
- Separate parametrized tests only when the setup or assertions differ significantly
Run ruff: prek .:ruff to fix lint issues.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: af-test3description: Write tests for Airflow backend API endpoints following project conventions. Use when this capability is needed.4---56# Airflow Test Writer78Write tests for Airflow backend API endpoints.910## Usage11```12/af-test <endpoint file path or description>13```1415## Test Location1617Tests mirror the source tree:18- `airflow-core/src/airflow/api_fastapi/core_api/routes/ui/foo.py`19- `airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_foo.py`2021## Conventions2223### Structure24- One test class per endpoint, named `Test<EndpointFunction>` (e.g. `TestGetPartitionedDagRuns`)25- All test methods inside the class, with descriptive names26- Auth tests in every class: `test_should_response_401`, `test_should_response_403`27- Use `pytestmark = pytest.mark.db_test` at module level28- Use `@pytest.fixture(autouse=True)` for cleanup2930### Parametrize over separate methods31- Prefer one parametrized test over multiple methods with similar setup32- Use `@pytest.mark.parametrize` with `ids` for all variants33- Vary inputs (counts, booleans, enums) and derive expected values in the test body34- Keep assertions generic enough to work across all parameter combinations3536Example: instead of `test_pending`, `test_fulfilled`, `test_partial`, write one `test_should_response_200` parametrized on `(num_assets, received_count, fulfilled)`.3738### Fixtures and helpers39- Use `dag_maker` fixture to create DAGs, call `dag_maker.sync_dagbag_to_db()` after40- Use `session` fixture for direct DB operations (add, flush, commit)41- Use `test_client` for authenticated requests, `unauthenticated_test_client` / `unauthorized_test_client` for auth tests42- Use `assert_queries_count` to verify query efficiency where existing tests do43- Cleanup helpers from `tests_common.test_utils.db`: `clear_db_dags`, `clear_db_serialized_dags`, `clear_db_apdr`, `clear_db_pakl`, etc.4445## Instructions46471. **Read the endpoint code** to understand the route, parameters, response model, and dependencies.48492. **Read 1-2 existing test files** in the same directory to match the local style. Use the closest neighbor (e.g. `test_assets.py` for asset-related endpoints).50513. **Write the test file** with:52 - Auth tests (401, 403) for each endpoint class53 - 404 for missing resources54 - One parametrized 200 test covering: happy path, edge cases (empty/partial data), and relevant filter/flag combinations55 - Separate parametrized tests only when the setup or assertions differ significantly56574. **Run ruff:** `prek .:ruff` to fix lint issues.5859---60> Converted and distributed by [TomeVault](https://tomevault.io/claim/guan404ming) — claim your Tome and manage your conversions.61<!-- tomevault:4.0:skill_md:2026-04-13 -->