Airflow - DAG integrity tests - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: variable

Viewed 1087

I am currently writing some airflow DAG integrity tests for the first time. I am coming across an error where some of my operators/tasks are referencing airflow variables, eg:

test_var= Variable.get("AIRFLOW_VAR_TEST_VAR")

When i run a integrity test using pytest, i get the below error:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: variable

I can work around this by replacing the Variable.get code with a hard-coded value, but wondering if there is a better way to deal with this error?

Thanks,

1 Answers

You should run

AIRFLOW__CORE__UNIT_TEST_MODE=True airflow db reset

This will initialise and re-create unit test sqlite database from scratch.

Alternatively you can run pytest with the airflow-specific switch --with-db-init switch which does the same.

Related