Airflow Python Unit Test?

。_饼干妹妹 提交于 2019-12-02 21:17:15

Test your operators like this:

class TestMyOperator(TestCase):

    def test_execute(self):
        dag = DAG(dag_id='foo', start_date=datetime.now())
        task = MyOperator(dag=dag, 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,
    )
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!