hello
2025年7月4日小于 1 分钟
Great—you’ve done the first step by installing Apache Airflow using:
pip install apache-airflowHere’s a clear step-by-step guide on what you need to do next to test your Airflow task using airflow tasks test:
✅ Step 1: Initialize Airflow Database
In your terminal:
airflow db migrate✅ This creates the necessary metadata database in AIRFLOW_HOME (default: ~/airflow).
✅ Step 3: Create Your DAG File
Create a folder:
mkdir -p ~/airflow/dagsSave your DAG file, e.g.,
~/airflow/dags/my_dag.py:
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime
def hello_world():
print("Hello from Airflow!")
with DAG(
dag_id='my_test_dag',
start_date=datetime(2023, 1, 1),
schedule_interval=None,
catchup=False,
tags=['example'],
) as dag:
task1 = PythonOperator(
task_id='say_hello',
python_callable=hello_world,
)✅ Key:
- DAG id:
my_test_dag - Task id:
say_hello
✅ Step 4: Test Your Task Without Running Scheduler
Run this in the terminal:
airflow tasks test my_test_dag say_hello 2024-07-04- You should see
Hello from Airflow!printed in the logs. - No scheduler, no webserver needed!
✅ Common Troubleshooting:
| Issue | Fix |
|---|---|
airflow: command not found | Try pip show apache-airflow to check install location; check PATH |
DAG not found | Make sure your my_dag.py is in ~/airflow/dags |
ModuleNotFoundError | Install missing Python packages used in your task |
✅ To recap what you need:
airflow db migrate- Put your DAG in
~/airflow/dags - Run
airflow tasks test dag_id task_id execution_date
👉 If you want, send me your exact task code and I can help you write the test command and check it step by step.