From e8bb1464679bab4438586a1a31b21f8ace961a7f Mon Sep 17 00:00:00 2001 From: pankajastro Date: Tue, 3 Jun 2025 19:44:03 +0530 Subject: [PATCH 1/7] Assert DagRun state --- tests/test_example_dags.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index 778e3e3a..03fe968d 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -12,6 +12,7 @@ from airflow.models.dagbag import DagBag from airflow.utils.db import create_default_connections from airflow.utils.session import provide_session +from airflow.utils.state import DagRunState from packaging.version import Version from . import utils as test_utils @@ -36,7 +37,8 @@ # Add HTTP operator DAG to ignored files for providers-http versions without HttpOperator try: - from airflow.providers.http.operators.http import HttpOperator + from airflow.providers.http.operators.http import HttpOperator # noqa: F401 + HTTP_OPERATOR_AVAILABLE = True except ImportError: HTTP_OPERATOR_AVAILABLE = False @@ -91,15 +93,17 @@ def test_example_dag(session, dag_id: str): # Skip http_operator_example_dag in older Airflow versions without HttpOperator if dag_id == "http_operator_example_dag" and not HTTP_OPERATOR_AVAILABLE: pytest.skip(f"Skipping {dag_id} because HttpOperator is not available") - - # Skip http_operator_example_dag in older Airflow versions + + # Skip http_operator_example_dag in older Airflow versions # since it has compatibility issues with our connection handling if dag_id == "http_operator_example_dag" and AIRFLOW_VERSION < Version("2.7.0"): pytest.skip(f"Skipping {dag_id} on Airflow version {AIRFLOW_VERSION}") - + # This feature is available since Airflow 2.5: # https://airflow.apache.org/docs/apache-airflow/stable/release_notes.html#airflow-2-5-0-2022-12-02 if AIRFLOW_VERSION >= Version("2.5"): - dag.test() + dagrun = dag.test() + assert dagrun.state == DagRunState.SUCCESS else: - test_utils.run_dag(dag) + dagrun = test_utils.run_dag(dag) + assert dagrun.state == DagRunState.SUCCESS From 3e2a547de84bfdedf56d41d4eebc2194322f424a Mon Sep 17 00:00:00 2001 From: pankajastro Date: Tue, 3 Jun 2025 19:49:19 +0530 Subject: [PATCH 2/7] Assert DagRun state --- tests/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.py b/tests/utils.py index afe46c1d..d7a5b8ba 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -97,7 +97,7 @@ def test_dag( print("conn_file_path", conn_file_path) - return dr, session + return dr def add_logger_if_needed(dag: DAG, ti: TaskInstance): From 9171af760ee87d509c9e7f2198f028c2d4d900fb Mon Sep 17 00:00:00 2001 From: pankajastro Date: Tue, 3 Jun 2025 19:54:05 +0530 Subject: [PATCH 3/7] Assert DagRun state --- tests/test_example_dags.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index 03fe968d..679f6f8b 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -103,7 +103,9 @@ def test_example_dag(session, dag_id: str): # https://airflow.apache.org/docs/apache-airflow/stable/release_notes.html#airflow-2-5-0-2022-12-02 if AIRFLOW_VERSION >= Version("2.5"): dagrun = dag.test() - assert dagrun.state == DagRunState.SUCCESS + if dagrun is not None: + assert dagrun.state == DagRunState.SUCCESS else: dagrun = test_utils.run_dag(dag) - assert dagrun.state == DagRunState.SUCCESS + if dagrun is not None: + assert dagrun.state == DagRunState.SUCCESS From 3d5b4b0a23a8c93e5ab0622b44a557dca64a1aa6 Mon Sep 17 00:00:00 2001 From: pankajastro Date: Wed, 4 Jun 2025 12:45:57 +0530 Subject: [PATCH 4/7] Ignore test --- tests/test_example_dags.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index 679f6f8b..46e0796c 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -33,6 +33,7 @@ ], "2.7": ["example_map_index_template.py"], "2.4": ["example_external_sensor_dag.py"], + "2.9": ["example_map_index_template.py"], } # Add HTTP operator DAG to ignored files for providers-http versions without HttpOperator From 77e728e617397605a5147521ff1c414476d8b395 Mon Sep 17 00:00:00 2001 From: pankajastro Date: Wed, 4 Jun 2025 13:00:24 +0530 Subject: [PATCH 5/7] Ignore test --- tests/test_example_dags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index 46e0796c..43772dcc 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -20,7 +20,7 @@ EXAMPLE_DAGS_DIR = Path(__file__).parent.parent / "dev/dags" AIRFLOW_IGNORE_FILE = EXAMPLE_DAGS_DIR / ".airflowignore" AIRFLOW_VERSION = Version(airflow.__version__) -IGNORED_DAG_FILES = ["example_callbacks.py"] +IGNORED_DAG_FILES = ["example_callbacks.py", "http_operator_example_dag.py"] MIN_VER_DAG_FILE_VER: dict[str, list[str]] = { # TaskFlow examples unrelated to dynamic task mapping work in earlier versions From 7b6d1afa1d24b83a2467b814241985244fb35cbe Mon Sep 17 00:00:00 2001 From: pankajastro Date: Wed, 4 Jun 2025 13:13:04 +0530 Subject: [PATCH 6/7] Ignore test --- tests/test_example_dags.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index 43772dcc..3d64d8a3 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -36,14 +36,6 @@ "2.9": ["example_map_index_template.py"], } -# Add HTTP operator DAG to ignored files for providers-http versions without HttpOperator -try: - from airflow.providers.http.operators.http import HttpOperator # noqa: F401 - - HTTP_OPERATOR_AVAILABLE = True -except ImportError: - HTTP_OPERATOR_AVAILABLE = False - @provide_session def get_session(session=None): @@ -91,22 +83,13 @@ def test_example_dag(session, dag_id: str): dag_bag = get_dag_bag() dag = dag_bag.get_dag(dag_id) - # Skip http_operator_example_dag in older Airflow versions without HttpOperator - if dag_id == "http_operator_example_dag" and not HTTP_OPERATOR_AVAILABLE: - pytest.skip(f"Skipping {dag_id} because HttpOperator is not available") - - # Skip http_operator_example_dag in older Airflow versions - # since it has compatibility issues with our connection handling - if dag_id == "http_operator_example_dag" and AIRFLOW_VERSION < Version("2.7.0"): - pytest.skip(f"Skipping {dag_id} on Airflow version {AIRFLOW_VERSION}") - # This feature is available since Airflow 2.5: # https://airflow.apache.org/docs/apache-airflow/stable/release_notes.html#airflow-2-5-0-2022-12-02 + dag_run = None if AIRFLOW_VERSION >= Version("2.5"): - dagrun = dag.test() - if dagrun is not None: - assert dagrun.state == DagRunState.SUCCESS + dag_run = dag.test() else: - dagrun = test_utils.run_dag(dag) - if dagrun is not None: - assert dagrun.state == DagRunState.SUCCESS + dag_run = test_utils.run_dag(dag) + + if dag_run is not None: + assert dag_run.state == DagRunState.SUCCESS From 8b888e6f1c355b14259b6ba9845d4ae4066dbcf6 Mon Sep 17 00:00:00 2001 From: pankajastro Date: Wed, 4 Jun 2025 13:19:44 +0530 Subject: [PATCH 7/7] Ignore test --- tests/test_example_dags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index 3d64d8a3..a2d4b398 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -20,7 +20,7 @@ EXAMPLE_DAGS_DIR = Path(__file__).parent.parent / "dev/dags" AIRFLOW_IGNORE_FILE = EXAMPLE_DAGS_DIR / ".airflowignore" AIRFLOW_VERSION = Version(airflow.__version__) -IGNORED_DAG_FILES = ["example_callbacks.py", "http_operator_example_dag.py"] +IGNORED_DAG_FILES = ["example_callbacks.py", "example_http_operator_task.py"] MIN_VER_DAG_FILE_VER: dict[str, list[str]] = { # TaskFlow examples unrelated to dynamic task mapping work in earlier versions