camilla-storytel opened a new issue, #39402:
URL: https://github.com/apache/airflow/issues/39402

   ### What do you see as an issue?
   
   Hi!
   I am trying to unit test my DAGs by following [this link in the AirFlow 
docs](https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html#unit-tests):
 
   
   ```
   import pytest
   
   from airflow.models import DagBag
   
   
   @pytest.fixture()
   def dagbag():
       return DagBag()
   
   
   def test_dag_loaded(dagbag):
       dag = dagbag.get_dag(dag_id="hello_world")
       assert dagbag.import_errors == {}
       assert dag is not None
       assert len(dag.tasks) == 1
   ```
   
   However, when I try to run this with `pytest`, I get this error:
   
   ```
   ../env/lib/python3.10/site-packages/sqlalchemy/engine/base.py:1910:
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ _ _ _
   
   self = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 
0x105bb66b0>, cursor = <sqlite3.Cursor object at 0x15c56bf40>
   statement = 'SELECT dag.dag_id AS dag_dag_id, dag.root_dag_id AS 
dag_root_dag_id, dag.is_paused AS dag_is_paused, dag.is_subdag AS...end, 
dag.next_dagrun_create_after AS dag_next_dagrun_create_after \nFROM dag \nWHERE 
dag.dag_id = ?\n LIMIT ? OFFSET ?'
   parameters = ('long-tail-recommender-0.0.1', 1, 0), context = 
<sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x15c713a30>
   
       def do_execute(self, cursor, statement, parameters, context=None):
   >       cursor.execute(statement, parameters)
   E       sqlite3.OperationalError: no such table: dag
   
   ../env/lib/python3.10/site-packages/sqlalchemy/engine/default.py:736: 
OperationalError
   
   The above exception was the direct cause of the following exception:
   ```
   
   I suspect I am lacking some local setup, but I don't really know which one 
and there is no further guidance in the documentation.
   
   ### Solving the problem
   
   If someone could please help me figure out why I am missing the `dag` table 
and what the proper setup would look like, I will happily open a PR to improve 
the documentaiton. 
   
   ### Anything else
   
   This occurs every time I run `pytest` on the unit test example. 
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to