Pytest plugin for Bigquery SQL
pytest-sql-bigquery is pytest-plugin which provides a sql-unitest-framework for BigQuery. This plugin adopts an end-to-end approch that runnning SQL test on SQL engines.
Yet anthoer approch to tst SQL code
See following SQL codes:
with dataset as (
select 1
union all select 2
)
, __check_sample as (
select 'test' as label, count(1) as actual, 2 as expected from dataset
)
select * from dataset
This code is minimal example including test case.
__check_sample is a test case which makes sure the dataset view has just 2 record.
Our idea is very simple: "Verify SQL code by SQL-self."
This plugin generate SQL test codes from SQL and executed them on SQL-engine such as BigQuery.
The advantages of this approch are
- SQL codes owns specification itself
- Provide portability of logic and its test codes.
- Free to hard-mocking database system
Get Started
Requirements
-
Python >= 3.7
-
sqlparse
-
google-cloud-bigquery (For BigQuery integration)
-
BigQuery (Google Cloud Project)
Install
pip install pytest-bigquery-sql
Then, set up confidist.py for pytest settings.
import pytest
from pytest_sql_bigquery.integrations.pytest import SQLReaderForChecking
class ChainPytestFile(pytest.File):
def __init__(self, path, parent, chains, **kwargs):
super().__init__(path, parent, **kwargs)
self.chains = chains
def collect(self):
for interpreter in self.chains:
yield from interpreter.collect()
def pytest_collect_file(parent, path):
if path.ext == ".sql":
return ChainPytestFile(
path, parent,
[
SQLReaderForChecking(path, parent),
])
Run test for examples/sql directory
pytest run -vv examples/sql
Metadata
Release files for pytest-sql-bigquery 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_sql_bigquery-0.0.3.tar.gz | 5.0 kB | Without provenance | Details for pytest_sql_bigquery-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_sql_bigquery-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for pytest_sql_bigquery-0.0.3-py3-none-any.whl |
Total release size: 10.3 kB
Release files / pytest_sql_bigquery-0.0.3.tar.gz
| Download URL | pytest_sql_bigquery-0.0.3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37a7e99c1d00a70dd9793144c4892483031a2c5d0946630f52dee5b8faa645e2
|
|
BLAKE2b-256 checksum How to use checksums |
5a8e12961d1e8927c367944a612b0bbaac510f632b58b86501afc46057f05ece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0 CPython/3.7.5 Darwin/18.7.0
|
Release files / pytest_sql_bigquery-0.0.3-py3-none-any.whl
| Download URL | pytest_sql_bigquery-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f65d4dfc0f1582625d3e8a95113e899287f081cd354b4a430ffa6f611f224023
|
|
BLAKE2b-256 checksum How to use checksums |
6d6fb30630efda258f0468e47c5dda275309ae38339be1f8b5527851596b880a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0 CPython/3.7.5 Darwin/18.7.0
|
Security for pytest-sql-bigquery 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.