'Test that post_execute hook is called with the Operator\'s result.
The result (\'error\') will cause an error to be raised and trapped.'

def test_post_execute_hook(self):

    class TestError(Exception, ):
        pass
    class TestOperator(PythonOperator, ):
        def post_execute(self, context, result):
            if (result == u'error'):
                raise TestError(u'expected    error.')
    dag = models.DAG(dag_id=u'test_post_execute_dag')
    task = TestOperator(task_id=u'test_operator', dag=dag, python_callable=(lambda : u'error'), owner=u'airflow', start_date=datetime.datetime(2017, 2, 1))
    ti = TI(task=task, execution_date=datetime.datetime.now())
    with self.assertRaises(TestError):
        ti.run()
