Skip to main content

Fake Snowflake Connector for Python. Run, mock and test Snowflake DB locally.

Project description

fakesnow ❄️

ci release PyPI PyPI - Downloads

Fake Snowflake Connector for Python. Run and mock Snowflake DB locally.

Install

pip install fakesnow

Usage

Run script.py with fakesnow:

fakesnow script.py

Or a module, eg: pytest

fakesnow -m pytest

fakesnow executes fakesnow.patch before running the script or module.

fakesnow.patch

To use fakesnow within your code:

import fakesnow
import snowflake.connector

with fakesnow.patch():
    conn = snowflake.connector.connect()

    print(conn.cursor().execute("SELECT 'Hello fake world!'").fetchone())

The following imports are automatically patched:

  • import snowflake.connector.connect
  • import snowflake.connector.pandas_tools.write_pandas

To patch modules that use the from ... import syntax, manually specify them, eg: if mymodule.py has the import:

from snowflake.connector.pandas_tools import write_pandas

Then patch it using:

with fakesnow.patch("mymodule.write_pandas"):
    ...

By default databases are in-memory. To persist databases between processes, specify a databases path:

with fakesnow.patch(db_path="databases/"):
    ...

pytest fixtures

pytest fixtures are provided for testing. Example conftest.py:

from typing import Iterator

import fakesnow.fixtures
import pytest

pytest_plugins = fakesnow.fixtures.__name__

@pytest.fixture(scope="session", autouse=True)
def setup(_fakesnow_session: None) -> Iterator[None]:
    # the standard imports are now patched
    ...
    yield

Or with from ... import patch targets:

from typing import Iterator

import fakesnow
import pytest

@pytest.fixture(scope="session", autouse=True)
def _fakesnow_session() -> Iterator[None]:
    with fakesnow.patch("mymodule.write_pandas"):
        yield

Implementation coverage

Partial support

  • date functions
  • regex functions
  • semi-structured data
  • tags
  • user management (See tests/test_users.py)

For more detail see tests/test_fakes.py

Caveats

  • The order of rows is non deterministic and may not match Snowflake unless ORDER BY is fully specified.
  • A more liberal Snowflake SQL dialect than a real Snowflake instance is supported, ie: some queries might pass using fakesnow that a real Snowflake instance would reject.

Contributing

See CONTRIBUTING.md to get started and develop in this repo.

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

fakesnow-0.9.10.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

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

fakesnow-0.9.10-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file fakesnow-0.9.10.tar.gz.

File metadata

  • Download URL: fakesnow-0.9.10.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for fakesnow-0.9.10.tar.gz
Algorithm Hash digest
SHA256 5bde2b3bd1959c00bfbe08d93473ee38e96efec483a95152f86bb5bc515de63c
MD5 f80aa45815ebfa7973e9c6a0bb64cc4e
BLAKE2b-256 706730df1d8f567c46cd804cebee9266af8130cbe41bfef68f8d76c0dd4ff00e

See more details on using hashes here.

File details

Details for the file fakesnow-0.9.10-py3-none-any.whl.

File metadata

  • Download URL: fakesnow-0.9.10-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for fakesnow-0.9.10-py3-none-any.whl
Algorithm Hash digest
SHA256 58b65066fa5078aaaf7807f007c5f6444365ef3915817b45e907d49af0ddac84
MD5 014e24493b3cc01e4c1d991d86d59dc3
BLAKE2b-256 29a8d25b2ede4e52e9f4e4b5550808e6be75850314bbed7a089cd2b3fd6c0b6b

See more details on using hashes here.

Supported by

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