Challenge - 5 Problems
Airflow DAG Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a simple DAG test run
You have a DAG with one task that prints 'Hello Airflow'. You run a unit test that triggers this task. What will be the output of the test command?
Apache Airflow
def test_hello_task(): ti = TaskInstance(task=hello_task, execution_date=datetime.now()) ti.run() print(ti.xcom_pull())
Attempts:
2 left
💡 Hint
Think about what xcom_pull returns if no value is pushed.
✗ Incorrect
The task prints 'Hello Airflow' but does not push any XCom value, so ti.xcom_pull() returns None.
🧠 Conceptual
intermediate1:30remaining
Purpose of mocking in DAG unit tests
Why do we use mocking when unit testing Airflow DAGs?
Attempts:
2 left
💡 Hint
Think about how to test code without relying on real external services.
✗ Incorrect
Mocking replaces external dependencies with fake ones so tests focus only on DAG logic.
❓ Troubleshoot
advanced2:00remaining
Diagnosing a failing DAG unit test
A unit test for a DAG task fails with the error: 'TaskInstanceStateError: Task instance is in state None'. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check how TaskInstance is created in tests.
✗ Incorrect
TaskInstance requires a valid execution_date to track state; missing it causes this error.
✅ Best Practice
advanced1:30remaining
Best practice for testing task dependencies in DAGs
Which approach best verifies task dependencies in an Airflow DAG unit test?
Attempts:
2 left
💡 Hint
Think about programmatic ways to verify dependencies.
✗ Incorrect
Accessing task attributes programmatically allows automated verification of dependencies.
🔀 Workflow
expert2:30remaining
Correct order of steps in unit testing an Airflow DAG
Arrange the following steps in the correct order for unit testing an Airflow DAG:
Attempts:
2 left
💡 Hint
Think about preparing the environment before running tests.
✗ Incorrect
First import DAG/tasks, then mock dependencies, create TaskInstances, then run and assert.