Repository: incubator-airflow Updated Branches: refs/heads/master f80138486 -> 76d11f24c
[AIRFLOW-102] Fix test_complex_template always succeeds Exceptions from on_success_callback are stomped on, meaning test_complex_template would never fail. Rather than follow the "success = True" pattern (which results in the lovely-to-track-down error message of `AssertionError: False is not true` I instead changed all these to have the verify method be execute -- meaning exceptions are propagated unchanged. Thanks to @sekikn in https://github.com/apache/incubator- airflow/pull/2375 for the info to track down what was going on. Closes #2375 Closes #3100 from ashb/template_tests_always_succeed Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/76d11f24 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/76d11f24 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/76d11f24 Branch: refs/heads/master Commit: 76d11f24c64abb53826b1bb99fe87a6bfc317c43 Parents: f801384 Author: Ash Berlin-Taylor <[email protected]> Authored: Sat Mar 10 15:18:11 2018 +0100 Committer: Fokko Driesprong <[email protected]> Committed: Sat Mar 10 15:18:11 2018 +0100 ---------------------------------------------------------------------- tests/core.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/76d11f24/tests/core.py ---------------------------------------------------------------------- diff --git a/tests/core.py b/tests/core.py index 45a6e34..03372db 100644 --- a/tests/core.py +++ b/tests/core.py @@ -488,7 +488,8 @@ class CoreTest(unittest.TestCase): def test_complex_template(self): def verify_templated_field(context): - self.assertEqual(context['ti'].task.some_templated_field['bar'][1], context['ds']) + self.assertEqual(context['ti'].task.some_templated_field['bar'][1], + context['ds']) t = OperatorSubclass( task_id='test_complex_template', @@ -496,8 +497,8 @@ class CoreTest(unittest.TestCase): 'foo': '123', 'bar': ['baz', '{{ ds }}'] }, - on_success_callback=verify_templated_field, dag=self.dag) + t.execute = verify_templated_field t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) def test_template_with_variable(self): @@ -505,7 +506,6 @@ class CoreTest(unittest.TestCase): Test the availability of variables in templates """ val = { - 'success': False, 'test_value': 'a test value' } Variable.set("a_variable", val['test_value']) @@ -513,22 +513,19 @@ class CoreTest(unittest.TestCase): def verify_templated_field(context): self.assertEqual(context['ti'].task.some_templated_field, val['test_value']) - val['success'] = True t = OperatorSubclass( task_id='test_complex_template', some_templated_field='{{ var.value.a_variable }}', - on_success_callback=verify_templated_field, dag=self.dag) + t.execute = verify_templated_field t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - self.assertTrue(val['success']) def test_template_with_json_variable(self): """ Test the availability of variables (serialized as JSON) in templates """ val = { - 'success': False, 'test_value': {'foo': 'bar', 'obj': {'v1': 'yes', 'v2': 'no'}} } Variable.set("a_variable", val['test_value'], serialize_json=True) @@ -536,15 +533,13 @@ class CoreTest(unittest.TestCase): def verify_templated_field(context): self.assertEqual(context['ti'].task.some_templated_field, val['test_value']['obj']['v2']) - val['success'] = True t = OperatorSubclass( task_id='test_complex_template', some_templated_field='{{ var.json.a_variable.obj.v2 }}', - on_success_callback=verify_templated_field, dag=self.dag) + t.execute = verify_templated_field t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - self.assertTrue(val['success']) def test_template_with_json_variable_as_value(self): """ @@ -552,7 +547,6 @@ class CoreTest(unittest.TestCase): accessed as a value """ val = { - 'success': False, 'test_value': {'foo': 'bar'} } Variable.set("a_variable", val['test_value'], serialize_json=True) @@ -560,15 +554,13 @@ class CoreTest(unittest.TestCase): def verify_templated_field(context): self.assertEqual(context['ti'].task.some_templated_field, u'{"foo": "bar"}') - val['success'] = True t = OperatorSubclass( task_id='test_complex_template', some_templated_field='{{ var.value.a_variable }}', - on_success_callback=verify_templated_field, dag=self.dag) + t.execute = verify_templated_field t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True) - self.assertTrue(val['success']) def test_template_non_bool(self): """
