|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +import pytest |
| 20 | + |
| 21 | + |
| 22 | +class TestDagTestExecutor: |
| 23 | + """Verifies that `dag.test()` executes cleanly via CLI and Python SDK across matrix configurations.""" |
| 24 | + |
| 25 | + @pytest.mark.parametrize("execution_type", ["cli", "python_sdk"]) |
| 26 | + @pytest.mark.parametrize("use_executor", ["true", "false"]) |
| 27 | + def test_dag_test_matrix_execution(self, compose_instance, execution_type, use_executor): |
| 28 | + """ |
| 29 | + Executes dag.test via both CLI and Python SDK modes with use_executor=True and False. |
| 30 | + This provides a true 4-case end-to-end integration verification. |
| 31 | + """ |
| 32 | + if execution_type == "cli": |
| 33 | + cmd_str = ( |
| 34 | + f"USE_EXECUTOR={use_executor} " |
| 35 | + "EXECUTE_DAG_TEST=true " |
| 36 | + "airflow dags test example_dag_test_executor" |
| 37 | + ) |
| 38 | + else: |
| 39 | + cmd_str = ( |
| 40 | + f"USE_EXECUTOR={use_executor} " |
| 41 | + "EXECUTE_DAG_TEST=true " |
| 42 | + "python /opt/airflow/airflow-e2e-tests/tests/airflow_e2e_tests/dags/example_dag_test_executor.py" |
| 43 | + ) |
| 44 | + |
| 45 | + stdout, stderr, exit_code = compose_instance.exec_in_container( |
| 46 | + service_name="airflow-scheduler", |
| 47 | + command=["sh", "-c", cmd_str], |
| 48 | + ) |
| 49 | + |
| 50 | + assert exit_code == 0, ( |
| 51 | + f"dag.test failed for mode='{execution_type}' with use_executor='{use_executor}'.\n" |
| 52 | + f"Exit code: {exit_code}.\nStdout: {stdout}\nStderr: {stderr}" |
| 53 | + ) |
0 commit comments