Provides a mock fixture for python bigquery client
Project description
pytest-bigquery-mock
Pytest plugin that provides a bq_client_mock
fixture.
This fixture mocks the google.cloud.bigquery.Client
class and provides a way to mock an API response using pytest.mark
, for example:
def function_that_calls_bigquery(bq_client):
row_iter = bq_client.query("SELECT * FROM table").result()
return row_iter
@pytest.mark.bq_query_return_data(
[
{
"query": "SELECT * FROM table",
"table": {
"columns": [
"id_row",
"name",
],
"rows": [
[1, "Alice"],
[2, "Pete"],
[3, "Steven"],
],
},
},
]
)
def test_function_that_calls_bigquery(bq_client_mock):
row_iter = function_that_calls_bigquery(bq_client_mock)
expected_row_dicts = [
{"id_row": 1, "name": "Alice"},
{"id_row": 2, "name": "Pete"},
{"id_row": 3, "name": "Steven"},
]
for row, expected_row in zip(row_iter, expected_row_dicts):
assert dict(row) == expected_row
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pytest-bigquery-mock-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d119adb8a33bf37c05ec71a81b67e7d6b792e03bf805e05cd2c5e9f2ef2113fe |
|
MD5 | 19c2f7ce004d2b9de8e2a3cb058b6790 |
|
BLAKE2b-256 | 92ecaafa2b46d515b06abe76f1bef9e1a18081e390a6ecea011da59598b11f2c |
Close
Hashes for pytest_bigquery_mock-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b75c5df69756dbf5b893cdee7a46bbb7d2fb44d3ca5f9a90bbe60ba6349babc |
|
MD5 | 9142b93a7f82d22eb2bd8c83765db5d1 |
|
BLAKE2b-256 | 2d88c76acb0147b979936a52fdc07886a912d271ab204c55b78ab0accff3b676 |