|
| 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 | + command = ["airflow", "dags", "test", "example_dag_test_executor"] |
| 34 | + else: |
| 35 | + # Executes the script directly via python inside the container |
| 36 | + command = ["python", "/files/dags/example_dag_test_executor.py"] |
| 37 | + |
| 38 | + stdout, stderr, exit_code = compose_instance.exec_in_container( |
| 39 | + service_name="airflow-scheduler", |
| 40 | + command=command, |
| 41 | + environment={ |
| 42 | + "USE_EXECUTOR": use_executor, |
| 43 | + "EXECUTE_DAG_TEST": "true", |
| 44 | + }, |
| 45 | + ) |
| 46 | + assert exit_code == 0, ( |
| 47 | + f"dag.test failed for mode='{execution_type}' with use_executor='{use_executor}'.\n" |
| 48 | + f"Exit code: {exit_code}.\nStdout: {stdout}\nStderr: {stderr}" |
| 49 | + ) |
0 commit comments