File tree Expand file tree Collapse file tree
blog/gcp-tech-blog/unit-test-dags-cloud-build Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121
2222
2323@pytest .fixture (autouse = True , scope = "function" )
24+ # The fixture `airflow_database` lives in composer/conftest.py.
2425def set_variables (airflow_database ):
2526 models .Variable .set ('gcp_project' , PROJECT_ID )
2627 yield
Original file line number Diff line number Diff line change 2020# The source of truth:
2121# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py
2222
23+ import tempfile
24+
25+
26+ # Airflow creates a config file at the installation, so we want to set
27+ # `AIRFLOW_HOME` envvar before running pytest.
28+
29+ _tmpdir = tempfile .TemporaryDirectory ()
30+
31+
2332TEST_CONFIG_OVERRIDE = {
2433 # You can opt out from the test for specific Python versions.
2534 # Skipping for Python 3.9 due to numpy compilation failure.
3544 # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
3645 # A dictionary you want to inject into your test. Don't put any
3746 # secrets here. These values will override predefined values.
38- "envs" : {},
47+ "envs" : {"AIRFLOW_HOME" : _tmpdir . name },
3948}
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515
16+ import os
17+ import tempfile
18+
1619import pytest
1720
1821
2124@pytest .fixture (scope = "session" )
2225def airflow_database ():
2326 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+
2436 # reset both resets and initializes a new database
2537 airflow .utils .db .resetdb (rbac = None ) # this command will change in Airflow 2.0
38+
39+ # Making sure we are using a data file there.
40+ assert (os .path .isfile (airflow_db ))
Original file line number Diff line number Diff line change 2020# The source of truth:
2121# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py
2222
23+ import tempfile
24+
25+
26+ # Airflow creates a config file at the installation, so we want to set
27+ # `AIRFLOW_HOME` envvar before running pytest.
28+
29+ _tmpdir = tempfile .TemporaryDirectory ()
30+
2331TEST_CONFIG_OVERRIDE = {
2432 # You can opt out from the test for specific Python versions.
2533 # Skipping for Python 3.9 due to numpy compilation failure.
3543 # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
3644 # A dictionary you want to inject into your test. Don't put any
3745 # secrets here. These values will override predefined values.
38- "envs" : {},
46+ "envs" : {"AIRFLOW_HOME" : _tmpdir . name },
3947}
Original file line number Diff line number Diff line change 1919
2020
2121@pytest .fixture (autouse = True , scope = "function" )
22+ # The fixture `airflow_database` lives in composer/conftest.py.
2223def set_variables (airflow_database ):
2324
2425 models .Variable .set ('gcs_bucket' , 'example_bucket' )
You can’t perform that action at this time.
0 commit comments