Skip to main content

pytest-clickhouse-mock

Pytest plugin with session- and function-scoped fixtures that replace clickhouse_driver.Client with a unittest.mock double. Use it to test code that talks to ClickHouse without running a server.

Python: 3.10+

Install

From PyPI:

uv add pytest-clickhouse-mock

Or with pip:

pip install pytest-clickhouse-mock

The plugin registers automatically when pytest loads (entry point clickhouse_mock).

Fixtures

Fixture Scope Purpose
fx_patch_clickhouse_client session, autouse Patches clickhouse_driver.Client for the whole test run
fx_clickhouse_client function Returns the mock instance for the current test; resets call state after each test

fx_patch_clickhouse_client is autouse: any clickhouse_driver.Client(...) in your tests gets the same mock class. Use fx_clickhouse_client when you need to configure execute, connection.connected, and other attributes.

Usage

import clickhouse_driver


def test_query(fx_clickhouse_client):
    fx_clickhouse_client.execute.return_value = [(1, 2, 3)]

    client = clickhouse_driver.Client("localhost")
    rows = client.execute("SELECT 1")

    assert rows == [(1, 2, 3)]
    fx_clickhouse_client.execute.assert_called_once_with("SELECT 1")


def test_connection(fx_clickhouse_client):
    client = clickhouse_driver.Client("localhost")

    assert client.connection.connected is True

After each test, fx_clickhouse_client resets return values and side effects so tests stay isolated.

Development

Repository: github.com/adalekin/pytest-clickhouse-mock

uv sync --group dev
uv run ruff check .
uv run ruff format --check .
uv run mypy pytest_clickhouse_mock
uv run pytest

License

MIT — see LICENSE.

Metadata

Release files for pytest-clickhouse-mock 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-clickhouse-mock 1.1.0
File Size Uploaded Provenance
pytest_clickhouse_mock-1.1.0.tar.gz 3.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-clickhouse-mock 1.1.0
File Interpreter ABI Platform
pytest_clickhouse_mock-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / pytest_clickhouse_mock-1.1.0.tar.gz

Download URL pytest_clickhouse_mock-1.1.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1af8ef5c39a6d3b2980648584b51cfa60d829e71477dad6653a39437f7eb4195
BLAKE2b-256 checksum
How to use checksums
e3aa452154b6b8e05028ed943fe732bc33ecc151fa20598bf8e5350a4ee79647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pytest_clickhouse_mock-1.1.0-py3-none-any.whl

Download URL pytest_clickhouse_mock-1.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f861112c5cb690e1ac950964606fa9302933e0abdd5f63ca1e267ccebd2062be
BLAKE2b-256 checksum
How to use checksums
245802fc248b5def487c95e8c7e62da45d5b9254f7c02ad6eb50473566d0c9a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pytest-clickhouse-mock 1.1.0

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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page