BigQuery fixtures and fixture factories for Pytest.
Project description
Pytest BQ
This is a pytest plugin in similar vein to pytest-postgres and pytest-kafka. It runs a local version of bigquery that you can use throughout your test suite.
This would have been much more painful without Mirakuru and bigquery-emulator; this is a simple wrapper around those tools.
Installation
This tool requires you to have a copy of the bigquery-emulator
binary somewhere on your path.
Depending upon your architecture you'll need a different version of the tool.
wget https://github.com/goccy/bigquery-emulator/releases/download/v0.6.1/bigquery-emulator-linux-amd64
mv bigquery-emulator-linux-amd64 /usr/local/bin/bigquery-emulator
To install this library:
pip install pytest-bq
Demo
# conftest.py
from pytest_bq.factories import client as bq_client
from pytest_bq.factories import proc as bq_process
# Create a process and a local client that targets that process.
bq_proc = bq_process.bq_proc(executable='/usr/local/bin/bigquery-emulator', project_id='test')
bqlocal = bq_client.bqlocal("bq_proc")
# tests/test_bq.py
from google.cloud import bigquery
from pytest_bq.executor.process import BQExecutor
def test_can_list_datasets(bq_proc: BQExecutor, bqlocal: bigquery.Client) -> None:
"""MVP to ensure everything works."""
test_dataset = "test_base"
bqlocal.create_dataset(test_dataset)
datasets = [x.full_dataset_id for x in bqlocal.list_datasets()]
assert test_dataset in datasets
Contributing
PRs are accepted.
# Install the dependencies with:
pip install .[test]
# Install pre-commit hooks.
pre-commit install
# Validate everything passes.
pre-commit run --all
# Run the tests.
pytest tests/
TODOs
- Validate
data_from_yaml
files. - Tools for dummy data generation.
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
Built Distribution
File details
Details for the file pytest_bq-0.0.2.tar.gz
.
File metadata
- Download URL: pytest_bq-0.0.2.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb8db2ec293cd6a7331ac6a7a835ac59bdc270eda748df61755e76956debc73e |
|
MD5 | 8909f4c67a66b803eb0518e1f1b24b23 |
|
BLAKE2b-256 | 321974913b8f2a8e82fd7f3aa6b1bf080f3f1b0cfa5a3c63b5b58471272a0c4a |
File details
Details for the file pytest_bq-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: pytest_bq-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e1148ed5aa9bd59fdcbbd4fb345c2f6f42308c2d42db1befa510d826ea8d430 |
|
MD5 | 26a12ec1d3897a3d20d608f61c2700ec |
|
BLAKE2b-256 | 22424c39d8e59c783f3a66da2cc03a0a8f8af47516f427787a6728734d40bb41 |