How to efficiently test my DAGs on a per-task basis in Airflow 3? #63941
Unanswered
GlenboLake
asked this question in
Q&A
Replies: 1 comment
-
|
Airflow 3 changed how task testing works. The Per-task testing in Airflow 3Option 1: Use
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am in the process of upgrading DAGs from Airflow 2.10 to 3.x. For each of my DAGs, I tend to have one test for each task that checks the output. A test for a PythonOperator may check that the correct XComs were set, and a SQLExecuteQueryOperator will usually check the final contents of the output table. An example DAG and test might look something like this:
I have several DAGs, amounting to over 1000 tests (including pytest.mark.parametrize) with about 700 instances of
ti.runas above. This takes about 7 minutes to run in Airflow 2.10.5. However, my attempts to migrate to Airflow 3 have resulted in the test suite taking a full 50 minutes now. I can only conclude that I have done something wrong.I can share the helper functions that I've written for Airflow 3 if requested, but what I'd really like to know is: Is there a preferred or correct way to test individual tasks? If possible, I want to try to avoid fully mocking out functions like
ti.xcom_pull(I want the test to fail if I pass an incorrect argument).I am aware that the easiest thing would be for me to test my functions and SQL templates directly. However, a large part of that is rendering templates, which requires a template context; is there a test-compatible version of Context available, or would I have to spin up my own?
Beta Was this translation helpful? Give feedback.
All reactions