You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2023/09/06 06:30:49 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #34108: Refactor: Consolidate import and usage of random

uranusjr commented on code in PR #34108:
URL: https://github.com/apache/airflow/pull/34108#discussion_r1316796894


##########
tests/models/test_cleartasks.py:
##########
@@ -580,25 +581,23 @@ def test_dags_clear(self):
             assert tis[i].max_tries == 1
 
         # test only_failed
-        from random import randint
-
-        failed_dag_idx = randint(0, len(tis) - 1)
-        tis[failed_dag_idx].state = State.FAILED
-        session.merge(tis[failed_dag_idx])
+        failed_dag = random.choice(tis)
+        failed_dag.state = State.FAILED
+        session.merge(failed_dag)
         session.commit()
 
         DAG.clear_dags(dags, only_failed=True)
 
-        for i in range(num_of_dags):
-            tis[i].refresh_from_db()
-            if i != failed_dag_idx:
-                assert tis[i].state == State.SUCCESS
-                assert tis[i].try_number == 3
-                assert tis[i].max_tries == 1
+        for ti in tis:

Review Comment:
   Wow this entire function can use a rewrite. (Not saying you should do it in this PR.)



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