I'd like to add some unit tests for our DAGs, but could not find any. Is there a framework for unit test for DAGs? There is an End-to-End testing framework that exists but I guess it's dead: https://issues.apache.org/jira/browse/AIRFLOW-79. Please suggest, Thanks!
Test your operators like this:
class TestMyOperator(TestCase):
    def test_execute(self):
        with DAG(dag_id="foo", start_date=datetime.now()):
            task = MyOperator(task_id="foo")
        ti = TaskInstance(task=task, execution_date=datetime.now())
        result = task.execute(ti.get_template_context())
        self.assertEqual(result, "foo")
Source
Currently I wasn't able to find anything better than simply using BashOperator:
with DAG('platform-test', start_date=datetime(2017, 8, 29)) as dag:
    test_command = "python3 -m unittest --verbose {}".format(platform_test_fname)
    op = BashOperator(
        task_id="platform-test",
        bash_command=test_command,
    )
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With