Skip to main content

Pytest fixtures that mock clickhouse-driver Client for unit tests.

Project description

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.

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

pytest_clickhouse_mock-1.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

pytest_clickhouse_mock-1.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_clickhouse_mock-1.1.0.tar.gz.

File metadata

  • Download URL: pytest_clickhouse_mock-1.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for pytest_clickhouse_mock-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1af8ef5c39a6d3b2980648584b51cfa60d829e71477dad6653a39437f7eb4195
MD5 11ff6adb4a87cf45b40e5af8b878d8e9
BLAKE2b-256 e3aa452154b6b8e05028ed943fe732bc33ecc151fa20598bf8e5350a4ee79647

See more details on using hashes here.

File details

Details for the file pytest_clickhouse_mock-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_clickhouse_mock-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for pytest_clickhouse_mock-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f861112c5cb690e1ac950964606fa9302933e0abdd5f63ca1e267ccebd2062be
MD5 b91f48388523b28098115fd82e7270a9
BLAKE2b-256 245802fc248b5def487c95e8c7e62da45d5b9254f7c02ad6eb50473566d0c9a5

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