Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 3c5f50b

Browse files
authored
test: mock BigQuery client for offline tests (#35)
1 parent b2340ce commit 3c5f50b

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

tests/conftest.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,31 @@ def target_folder_path(request: FixtureRequest) -> str:
7575
defaulting to "tests/".
7676
""" # noqa: E501
7777
return request.config.getoption("--target_folder_path")
78-
return request.config.getoption("--target_folder_path")
78+
79+
80+
@fixture(autouse=True)
81+
def mock_bigquery_client(mocker: FixtureRequest) -> None:
82+
"""Mock bigquery Client to prevent actual API calls during testing."""
83+
from unittest.mock import MagicMock
84+
85+
mock_client = mocker.patch("dataform2looker.database_mappers.bigquery.Client")
86+
mock_instance = mock_client.return_value
87+
88+
def get_table_side_effect(table_id: str) -> MagicMock:
89+
mock_table = MagicMock()
90+
91+
mock_field1 = MagicMock()
92+
mock_field1.name = "id"
93+
mock_field1.description = "Primary Key"
94+
mock_field1.field_type = "STRING"
95+
96+
mock_field2 = MagicMock()
97+
mock_field2.name = "created_at"
98+
mock_field2.description = "Creation date"
99+
mock_field2.field_type = "TIMESTAMP"
100+
101+
mock_table.schema = [mock_field1, mock_field2]
102+
return mock_table
103+
104+
mock_instance.get_table.side_effect = get_table_side_effect
105+
return mock_instance

0 commit comments

Comments
 (0)