You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/12/25 10:31:21 UTC

[airflow] branch main updated: Fix flaky test_get_context_in_old_style_context_task test (#28585)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new ba2c790bf3 Fix flaky test_get_context_in_old_style_context_task test (#28585)
ba2c790bf3 is described below

commit ba2c790bf3eb70175c97b2e7a8aaeff17d988f09
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sun Dec 25 11:30:59 2022 +0100

    Fix flaky test_get_context_in_old_style_context_task test (#28585)
    
    The test was flaky because it was passing schedule "@once" as
    default_args (wrongly) - as the result this test was set to
    the default "daily" and since start date was set to 1st Jan 2022
    it executed longer and longer every day (running the Python
    Operator for every day between 1st Jan and now.
    
    This PR cahnges the test to correctly pass "@once" schedule via the
    `schedule' parameter.
---
 tests/operators/test_python.py | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/tests/operators/test_python.py b/tests/operators/test_python.py
index 8f6c089f08..6bf79f5956 100644
--- a/tests/operators/test_python.py
+++ b/tests/operators/test_python.py
@@ -924,21 +924,9 @@ class TestPythonVirtualenvOperator(BasePythonTest):
             *PythonVirtualenvOperator.AIRFLOW_SERIALIZABLE_CONTEXT_KEYS,
             *intentionally_excluded_context_keys,
         }
-
         assert set(context) == declared_keys
 
 
-DEFAULT_ARGS = {
-    "owner": "test",
-    "depends_on_past": True,
-    "start_date": timezone.datetime(2022, 1, 1),
-    "end_date": datetime.today(),
-    "schedule_interval": "@once",
-    "retries": 1,
-    "retry_delay": timedelta(minutes=1),
-}
-
-
 class TestCurrentContext:
     def test_current_context_no_context_raise(self):
         with pytest.raises(AirflowException):
@@ -1000,14 +988,24 @@ def clear_db():
     clear_db_runs()
 
 
+DEFAULT_ARGS = {
+    "owner": "test",
+    "depends_on_past": True,
+    "start_date": datetime(2022, 1, 1),
+    "end_date": datetime.today(),
+    "retries": 1,
+    "retry_delay": timedelta(minutes=1),
+}
+
+
 @pytest.mark.usefixtures("clear_db")
 class TestCurrentContextRuntime:
     def test_context_in_task(self):
-        with DAG(dag_id="assert_context_dag", default_args=DEFAULT_ARGS):
+        with DAG(dag_id="assert_context_dag", default_args=DEFAULT_ARGS, schedule="@once"):
             op = MyContextAssertOperator(task_id="assert_context")
             op.run(ignore_first_depends_on_past=True, ignore_ti_state=True)
 
     def test_get_context_in_old_style_context_task(self):
-        with DAG(dag_id="edge_case_context_dag", default_args=DEFAULT_ARGS):
+        with DAG(dag_id="edge_case_context_dag", default_args=DEFAULT_ARGS, schedule="@once"):
             op = PythonOperator(python_callable=get_all_the_context, task_id="get_all_the_context")
             op.run(ignore_first_depends_on_past=True, ignore_ti_state=True)