Skip to content

Commit dfd321a

Browse files
authored
chore: set airflow as library for some tests (#2265)
* chore: set airflow as library for some tests * remove duplicate fixture
1 parent 44c6be3 commit dfd321a

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from unittest import mock
3+
4+
import pytest
5+
6+
7+
@pytest.fixture
8+
def set_airflow_as_library():
9+
with mock.patch.dict(os.environ, {"_AIRFLOW__AS_LIBRARY": "1"}):
10+
yield

tests/schedulers/airflow/operators/test_hwm_sensor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
)
1414
from sqlmesh.utils.date import to_datetime
1515

16+
pytest_plugins = ["tests.schedulers.airflow.operators.fixtures"]
1617
pytestmark = pytest.mark.airflow
1718

1819

19-
def test_no_current_hwm(mocker: MockerFixture, make_snapshot, random_name):
20+
def test_no_current_hwm(mocker: MockerFixture, make_snapshot, random_name, set_airflow_as_library):
2021
this_snapshot = make_snapshot(SqlModel(name="this", query=parse_one("select 1, ds")))
2122
this_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
2223

@@ -43,7 +44,7 @@ def test_no_current_hwm(mocker: MockerFixture, make_snapshot, random_name):
4344
get_snapshots_mock.assert_called_once_with([target_snapshot.table_info])
4445

4546

46-
def test_current_hwm_below_target(mocker: MockerFixture, make_snapshot):
47+
def test_current_hwm_below_target(mocker: MockerFixture, make_snapshot, set_airflow_as_library):
4748
this_snapshot = make_snapshot(
4849
SqlModel(name="this", query=parse_one("select 1, ds")), version="a"
4950
)
@@ -82,7 +83,7 @@ def test_current_hwm_below_target(mocker: MockerFixture, make_snapshot):
8283
get_snapshots_mock.assert_called_once_with([target_snapshot_v1.table_info])
8384

8485

85-
def test_current_hwm_above_target(mocker: MockerFixture, make_snapshot):
86+
def test_current_hwm_above_target(mocker: MockerFixture, make_snapshot, set_airflow_as_library):
8687
this_snapshot = make_snapshot(
8788
SqlModel(name="this", query=parse_one("select 1, ds")), version="a"
8889
)
@@ -115,7 +116,7 @@ def test_current_hwm_above_target(mocker: MockerFixture, make_snapshot):
115116
get_snapshots_mock.assert_called_once_with([target_snapshot_v1.table_info])
116117

117118

118-
def test_hwm_external_sensor(mocker: MockerFixture, make_snapshot):
119+
def test_hwm_external_sensor(mocker: MockerFixture, make_snapshot, set_airflow_as_library):
119120
snapshot = make_snapshot(
120121
SqlModel(
121122
name="this",

tests/schedulers/airflow/operators/test_targets.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from sqlmesh.schedulers.airflow.operators import targets
1919
from sqlmesh.utils.date import to_datetime
2020

21+
pytest_plugins = ["tests.schedulers.airflow.operators.fixtures"]
2122
pytestmark = pytest.mark.airflow
2223

2324

@@ -29,7 +30,9 @@ def model() -> Model:
2930
)
3031

3132

32-
def test_evaluation_target_execute(mocker: MockerFixture, make_snapshot: t.Callable, model: Model):
33+
def test_evaluation_target_execute(
34+
mocker: MockerFixture, make_snapshot: t.Callable, model: Model, set_airflow_as_library
35+
):
3336
interval_ds = to_datetime("2022-01-01")
3437
logical_ds = to_datetime("2022-01-02")
3538

@@ -76,7 +79,9 @@ def test_evaluation_target_execute(mocker: MockerFixture, make_snapshot: t.Calla
7679
)
7780

7881

79-
def test_evaluation_target_execute_seed_model(mocker: MockerFixture, make_snapshot: t.Callable):
82+
def test_evaluation_target_execute_seed_model(
83+
mocker: MockerFixture, make_snapshot: t.Callable, set_airflow_as_library
84+
):
8085
interval_ds = to_datetime("2022-01-01")
8186
logical_ds = to_datetime("2022-01-02")
8287

@@ -135,7 +140,9 @@ def test_evaluation_target_execute_seed_model(mocker: MockerFixture, make_snapsh
135140
)
136141

137142

138-
def test_cleanup_target_execute(mocker: MockerFixture, make_snapshot: t.Callable, model: Model):
143+
def test_cleanup_target_execute(
144+
mocker: MockerFixture, make_snapshot: t.Callable, model: Model, set_airflow_as_library
145+
):
139146
snapshot = make_snapshot(model)
140147
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
141148

@@ -181,7 +188,7 @@ def test_cleanup_target_execute(mocker: MockerFixture, make_snapshot: t.Callable
181188

182189

183190
def test_cleanup_target_skip_execution(
184-
mocker: MockerFixture, make_snapshot: t.Callable, model: Model
191+
mocker: MockerFixture, make_snapshot: t.Callable, model: Model, set_airflow_as_library
185192
):
186193
snapshot = make_snapshot(model)
187194
snapshot.version = "test_version"

0 commit comments

Comments
 (0)