You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/01/06 04:15:56 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #19194: Refactor ti clear next method kwargs tests

uranusjr commented on a change in pull request #19194:
URL: https://github.com/apache/airflow/pull/19194#discussion_r779288752



##########
File path: tests/models/test_taskinstance.py
##########
@@ -483,50 +483,32 @@ def task_function(ti):
         ti.state == state
 
     @pytest.mark.parametrize(
-        "state",
-        [State.FAILED, State.SKIPPED, State.SUCCESS, State.UP_FOR_RESCHEDULE, State.UP_FOR_RETRY],
+        "state, exception_type, retries",
+        [
+            (State.FAILED, AirflowException, 0),
+            (State.SKIPPED, AirflowSkipException, 0),
+            (State.SUCCESS, None, 0),
+            (State.UP_FOR_RESCHEDULE, AirflowRescheduleException(timezone.utcnow()), 0),
+            (State.UP_FOR_RETRY, AirflowException, 1),
+        ],
     )
-    def test_task_wipes_next_fields(self, session, state, dag_maker):
+    def test_task_wipes_next_fields(self, session, dag_maker, state, exception_type, retries):
         """
-        Test that ensures that tasks wipe their next_method and next_kwargs
-        when they go into a state of FAILED, SKIPPED, SUCCESS, UP_FOR_RESCHEDULE, or UP_FOR_RETRY.
+        Test that ensures that tasks wipe their next_method and next_kwargs for the configured states:
+        FAILED, SKIPPED, SUCCESS, UP_FOR_RESCHEDULE, UP_FOR_RETRY.
         """
 
-        def failure():
-            raise AirflowException
-
-        def skip():
-            raise AirflowSkipException
-
-        def success():
-            return None
-
-        def reschedule():
-            reschedule_date = timezone.utcnow()
-            raise AirflowRescheduleException(reschedule_date)
-
-        _retries = 0
-        _retry_delay = datetime.timedelta(seconds=0)
-
-        if state == State.FAILED:
-            _python_callable = failure
-        elif state == State.SKIPPED:
-            _python_callable = skip
-        elif state == State.SUCCESS:
-            _python_callable = success
-        elif state == State.UP_FOR_RESCHEDULE:
-            _python_callable = reschedule
-        elif state in [State.FAILED, State.UP_FOR_RETRY]:
-            _python_callable = failure
-            _retries = 1
-            _retry_delay = datetime.timedelta(seconds=2)
+        def _raise_af_exception(exception_type):

Review comment:
       ```suggestion
           def _raise_if_exception(exception_type):
   ```
   
   Probably? Or does `af` stand for Airflow?

##########
File path: tests/models/test_taskinstance.py
##########
@@ -537,10 +519,10 @@ def reschedule():
         session.commit()
 
         ti.task = task
-        if state in [State.FAILED, State.UP_FOR_RETRY]:
+        if exception_type == AirflowException:

Review comment:
       This does not correctly cover the `AirflowRescheduleException(timezone.utcnow())` case. It’s probably better to change `exception_type` to `exception` instead and always instantiate to avoid this subtle issue caused by `exception_type` may be either a type or an instance.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org