Skip to content

Conversation

@Shekharrajak
Copy link

@Shekharrajak Shekharrajak commented Dec 31, 2025

closes: #59319

Summary

Adds end-to-end (E2E) tests for dag.test() method, especially validating use_executor=True mode which was previously untested in E2E environment.

What's Changed

  • New E2E test module: airflow-e2e-tests/tests/airflow_e2e_tests/basic_tests/test_dag_test_method.py
  • Test DAGs: Created 4 test DAGs covering different scenarios:
    • test_dag_test_simple.py: Linear DAG execution
    • test_dag_test_xcom.py: XCom passing between tasks
    • test_dag_test_branching.py: Conditional execution paths
    • test_dag_test_task_groups.py: Nested task groups

Testing

  • Tests execute dag.test() inside Airflow scheduler container via testcontainers
  • Validates both use_executor=False and use_executor=True modes
  • breeze testing airflow-e2e-tests --python 3.10 -- tests/airflow_e2e_tests/basic_tests/test_dag_test_method.py -v tests passed .

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

- Add test_dag_test_simple.py: Simple linear DAG with bash and Python tasks
- Add test_dag_test_xcom.py: DAG demonstrating XCom passing between tasks
- Add test_dag_test_branching.py: DAG with branching logic using BranchPythonOperator
- Add test_dag_test_task_groups.py: DAG with nested task groups

These DAGs will be used to test dag.test() method in e2e environment.
- Add comprehensive test suite for dag.test() with use_executor=True and False
- Test simple DAG, XCom passing, branching, and task groups scenarios
- Execute tests inside Airflow scheduler container using exec_in_container
- Validate DagRun state and all task instance states after execution

Fixes apache#59319
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 31, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack
Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

from airflow_e2e_tests.conftest import _E2ETestState


def _execute_dag_test(dag_id: str, use_executor: bool = False) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to follow the existed e2e test convention as example. So instead of defining explicit ORM session query python code as str, we could take airflow-e2e-tests/tests/airflow_e2e_tests/remote_log_tests/test_remote_logging.py as example then use AirflowClient instead of the python code as string pattern here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for review : new commit 2c8bacf

from airflow.providers.standard.operators.python import BranchPythonOperator
from airflow.sdk import DAG, task


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these example dags, not sure would it be a good idea to just add symbolic link for existing example dag (e.g. airflow-core/src/airflow/example_dags/example_xcom.py )

cc @gopidesupavan WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the example dags will be loaded part of airflow e2e tests as we use this file https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/docker-compose/docker-compose.yaml#L65 and it has load_examples set it true.

So its better to use those example dags to test. @Shekharrajak can you please use the existing example dags instead of creating new ones..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants