Repository navigation
How to test a DAG with an intentionally-failing task and ONE_FAILED / ALL_FAILED trigger rule #32831
Replies: 2 comments
I revisited this and this does seem to be a working approach, but much slower: dag.clear()
dag.run(
start_date=execution_date,
end_date=datetime.now(),
executor=DebugExecutor(),
run_at_least_once=True,
disable_retry=True,
)If a task fails, this will raise a |
|
It appears that Airflow 2.7.0, via #32820, unintentionally (❓) fixed the way It's not obvious to me, given that implementation, how to assert in a test what specific exceptions were raised by which tasks, however. This is also not documented in the changelog as far as I can tell. |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
We are using
dag.test()(introduced in 2.5) to run "whole-DAG" unit/integration tests.dag.test()mostly works well when all the tasks succeed. But it doesn't work when a task fails. One manifestation of this is #31944. Another limitation is with testingtrigger_rule='one_failed'ortrigger_rule='all_failed'in a DAG where a task is expected to fail.For example:
If I want to unit-test this:
I would like the DAG to run through, with the
raiseint2_failtriggeringmop_up, and then in place of...to check the task states of the completed tasks, etc.But the
my_dag.test()line simply raises theRuntimeErrorfromt2_failand stops the DAG run.(I've also tried this with the older
DebugExecutorapproach and that also raises and does not runmop_up, though in a different way.)How can I run a DAG in a unit test, in which a task is expected to fail, and with the DAG continuing to downstream tasks?
Thank you!
All reactions