yuqian90 commented on a change in pull request #7038: [AIRFLOW-4495] allow 
externally triggered dags to run for future exec dates
URL: https://github.com/apache/airflow/pull/7038#discussion_r365525918
 
 

 ##########
 File path: tests/ti_deps/deps/test_runnable_exec_date_dep.py
 ##########
 @@ -37,14 +37,14 @@ def _get_task_instance(self, execution_date, 
dag_end_date=None, task_end_date=No
     @freeze_time('2016-01-01')
     def test_exec_date_after_end_date(self):
         """
-        If the dag's execution date is in the future this dep should fail
+        If the dag's execution date is in the future this dep should succeed
         """
         ti = self._get_task_instance(
             dag_end_date=datetime(2016, 1, 3),
             task_end_date=datetime(2016, 1, 3),
             execution_date=datetime(2016, 1, 2),
         )
-        self.assertFalse(RunnableExecDateDep().is_met(ti=ti))
+        self.assertTrue(RunnableExecDateDep().is_met(ti=ti))
 
 Review comment:
   @tooptoop4 , in some sense what you discovered is a flaw in the test itself. 
Since the dag in the test is a Mock object, `bool(dag.allow_future_exec_dates)` 
is always True (that's how Mock objects behave).
   
   So you can easily fix the test, and also like @kaxil  suggested, you should 
add a test for the scenarios where allow_future_exec_dates is True and False. 
   
   Here's what I suggest. In the following snippet, 
`test_exec_date_after_end_date` is what the original test tries to test. You 
should also add `test_exec_date_after_end_date_allow_future_exec_dates` which 
sets `allow_future_exec_dates` to True to test the new scenario your PR 
creates. Note that difference in the comments and in the assertTrue vs 
assertFalse.
   
   ```python
   class TestRunnableExecDateDep(unittest.TestCase):
   
       def _get_task_instance(self, execution_date, dag_end_date=None, 
task_end_date=None,
                              allow_future_exec_dates=False):
           dag = Mock(end_date=dag_end_date)
           dag.allow_future_exec_dates = allow_future_exec_dates
           task = Mock(dag=dag, end_date=task_end_date)
           return TaskInstance(task=task, execution_date=execution_date)
   
       @freeze_time('2016-01-01')
       def test_exec_date_after_end_date(self):
           """
           If the dag's execution date is in the future this dep should fail
           """
           ti = self._get_task_instance(
               dag_end_date=datetime(2016, 1, 3),
               task_end_date=datetime(2016, 1, 3),
               execution_date=datetime(2016, 1, 2),
           )
           self.assertFalse(RunnableExecDateDep().is_met(ti=ti))
   
       @freeze_time('2016-01-01')
       def test_exec_date_after_end_date_allow_future_exec_dates(self):
           """
           If the dag's execution date is in the future and 
allow_future_exec_dates is True,
           this dep should pass
           """
           ti = self._get_task_instance(
               dag_end_date=datetime(2016, 1, 3),
               task_end_date=datetime(2016, 1, 3),
               execution_date=datetime(2016, 1, 2),
               allow_future_exec_dates=True
           )
           self.assertTrue(RunnableExecDateDep().is_met(ti=ti))
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to