Skip to content

Commit dc388f7

Browse files
committed
fix!: Fix problem with failing dags tests on test all
1 parent cdfaeb7 commit dc388f7

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

tests/unit/dags/conftest.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
import os
22
import tempfile
3+
from typing import Generator
34

45
import pytest
56
from airflow.models import DagBag, Variable
67
from airflow.timetables.trigger import CronTriggerTimetable
78
from airflow.utils.db import resetdb, initdb
9+
810
from dags.daily_materialized_views_update import DAILY_MATERIALISED_VIEWS_DAG_NAME
911
from dags.fetch_notices_by_date import FETCHER_DAG_NAME
1012
from tests import AIRFLOW_DAG_FOLDER
1113

14+
1215
@pytest.fixture(scope="session", autouse=True)
13-
def setup_airflow():
14-
# Setup
16+
def setup_airflow_for_all_tests() -> Generator[None, None, None]:
1517
temp_db_file = tempfile.NamedTemporaryFile(mode="w+", suffix=".db")
1618
os.environ["AIRFLOW__CORE__SQL_ALCHEMY_CONN"] = f"sqlite:///{temp_db_file.name}"
1719
os.environ["AIRFLOW__CORE__LOAD_EXAMPLES"] = "False"
1820
os.environ["AIRFLOW__CORE__UNIT_TEST_MODE"] = "True"
19-
initdb(use_migration_files=False)
20-
21-
# Run tests
21+
resetdb()
22+
initdb()
2223
yield
24+
if os.path.exists(temp_db_file.name):
25+
temp_db_file.close()
2326

24-
# Cleanup
25-
temp_db_file.close()
2627

2728
@pytest.fixture
28-
def dag_bag(dag_materialised_view_update_schedule_variable_name, dag_fetch_schedule_variable_name) -> DagBag:
29+
def dag_bag(dag_materialised_view_update_schedule_variable_name: str,
30+
dag_fetch_schedule_variable_name: str) -> DagBag:
2931
Variable.delete(key=dag_materialised_view_update_schedule_variable_name)
3032
Variable.delete(key=dag_fetch_schedule_variable_name)
3133
return DagBag(
3234
dag_folder=AIRFLOW_DAG_FOLDER,
33-
include_examples=False, #Same as: os.environ["AIRFLOW__CORE__LOAD_EXAMPLES"] = "False"
35+
include_examples=False, # Same as: os.environ["AIRFLOW__CORE__LOAD_EXAMPLES"] = "False"
3436
read_dags_from_db=False,
3537
collect_dags=True)
3638

0 commit comments

Comments
 (0)