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:
Install and use
Install the plugin with
pip install pytest-bigquery-mock
Then, in your conftest.py
file add pytest-bigquery-mock
to your list of plugins
plugins = ["pytest-bigquery-mock"]
This allows you to use the bq_client_mock
fixture in your pytest tests.
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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 737b0ad80b3a59f51ef49c64bce3d60d77a6e3cfdd18a927193a4d245bc4b28f |
|
MD5 | a2d243bb833cc2cafdf3d462af363cd3 |
|
BLAKE2b-256 | c146ac75e578a745d1d9e0e226408a9d8dc52c983bc4cdf9bde8a1532e9afbe7 |
Close
Hashes for pytest_bigquery_mock-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a092afcc1523a24fdfb2b148b1357b8e38c57ed7f45ab624e368152db88bf681 |
|
MD5 | 2e17e102b3841b88b2ebbca64fa0f270 |
|
BLAKE2b-256 | ad35b06233ae64425f9380069ddfb4d5d575dc4ea072782a286d4140c694cbaa |