Skip to main content

Provides a mock fixture for python bigquery client

Project description


Pytest plugin that provides a bq_client_mock fixture. This fixture mocks the 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 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

            "query": "SELECT * FROM table",
            "table": {
                "columns": [
                "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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-bigquery-mock-0.1.2.tar.gz (3.0 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page