|
| 1 | +# Copyright 2021 Google LLC |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | + |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +import os |
| 17 | + |
| 18 | +import pytest |
| 19 | + |
| 20 | + |
| 21 | +# this fixture initializes the Airflow DB once per session |
| 22 | +# it is used by DAGs in both the blogs and workflows directories, |
| 23 | +# unless there exists a conftest at a lower level |
| 24 | +@pytest.fixture(scope="session") |
| 25 | +def airflow_database(): |
| 26 | + import airflow.utils.db |
| 27 | + |
| 28 | + # We use separate directory for local db path per session |
| 29 | + # by setting AIRFLOW_HOME env var, which is done in noxfile_config.py. |
| 30 | + |
| 31 | + assert "AIRFLOW_HOME" in os.environ |
| 32 | + |
| 33 | + airflow_home = os.environ["AIRFLOW_HOME"] |
| 34 | + airflow_db = f"{airflow_home}/airflow.db" |
| 35 | + |
| 36 | + # reset both resets and initializes a new database |
| 37 | + airflow.utils.db.resetdb() |
| 38 | + |
| 39 | + # Making sure we are using a data file there. |
| 40 | + assert os.path.isfile(airflow_db) |
0 commit comments