Skip to main content

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

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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_bigquery_mock-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest-bigquery-mock-0.1.2.tar.gz.

File metadata

  • Download URL: pytest-bigquery-mock-0.1.2.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.13

File hashes

Hashes for pytest-bigquery-mock-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cb31fb17a93bbaff69fca545092fbffa111310b9b11c843b3f26b0117a37215d
MD5 1ecb6e7ec6e7476a99cac80f0054f55f
BLAKE2b-256 208aea884e105a452db251a53d5e4d23c67613ced1752fb2c59752ae64d5fd7b

See more details on using hashes here.

File details

Details for the file pytest_bigquery_mock-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_bigquery_mock-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 57ef3085731a84cf377815e5416204d516383c35069d57d3e5ba6f8cc4b21da8
MD5 167fdce934763c711a32eaa943ddbf52
BLAKE2b-256 c56573afce07ed8cfbc86f51f013dc65f0e2e4e718aa705d5bf7e875d923c2b6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page