Testing Airflow workflows - ensuring your DAGs work before going into production
summary
Walks through concrete tests and tools: unit tests that call operator.execute for Python and Bash operators (note xcom_push behavior), using pytest fixtures to supply tempdirs and contexts, a parameterized dag integrity test that imports every DAG and detects cycles, mocking hooks with pytest-mock and patching HttpHook.run, and spinning up a real Postgres via pytest-docker-tools with init SQL to validate a Postgres-to-local operator. Shows airflow test vs airflow tasks test, the debug executor and using ipdb for breakpoints.
AI-written summary · about
chapters (12)
- 0:00Introduction and background
- 2:12Testing challenges in airflow
- 5:04Challenges of testing workflows
- 8:52Unit testing airflow components
- 12:55Testing operators and context
- 18:55Pytest fixtures for airflow
- 25:50Implementing helper functions
- 31:05Dag integrity and cycle tests
- 34:25Mocking external dependencies
- 38:23Dockerized testing environments
- 43:58Debugging airflow tasks
- 47:43Conclusion and Q&A
