Skip to content

Commit 7ea86a7

Browse files
committed
Make ClickHouse version configurable
1 parent 2f11eed commit 7ea86a7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

tests/conftest.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from datetime import datetime
33
from decimal import Decimal
4+
import os
45

56
import clickhouse_sqlalchemy
67
import pytest
@@ -17,13 +18,34 @@ def pytest_collection_modifyitems(items):
1718
item.add_marker('asyncio')
1819

1920

21+
def pytest_addoption(parser):
22+
parser.addoption(
23+
'--clickhouse-version', default=None,
24+
help='use specified version of ClickHouse',
25+
)
26+
27+
2028
@pytest.fixture(scope='session')
21-
def dsn(docker_services):
29+
def dsn(request, docker_services):
30+
ch_version = request.config.getoption('--clickhouse-version')
31+
if ch_version is not None:
32+
os.environ['CLICKHOUSE_VERSION'] = ch_version
2233
docker_services.start('clickhouse-server')
2334
public_port = docker_services.wait_for_service('clickhouse-server', 8123)
2435
return f'clickhouse://{docker_services.docker_ip}:{public_port}'
2536

2637

38+
@pytest.fixture
39+
async def clickhouse_version(dsn):
40+
if not hasattr(pytest, 'clickhouse_version'):
41+
async with aiochsa.connect(dsn) as conn:
42+
version = await conn.fetchval('SELECT version()')
43+
pytest.clickhouse_version = tuple(
44+
int(num) for num in version.split('.')
45+
)
46+
return pytest.clickhouse_version
47+
48+
2749
@pytest.fixture
2850
async def pool(dsn):
2951
async with aiochsa.create_pool(dsn) as pool:

tests/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ version: '2.1'
33
services:
44

55
clickhouse-server:
6-
image: yandex/clickhouse-server
6+
image: "yandex/clickhouse-server:${CLICKHOUSE_VERSION:-latest}"
77
ports:
88
- 8123

tests/test_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ async def test_as_is_round(conn, value):
175175
],
176176
ids = parametrized_id,
177177
)
178-
async def test_zero_dates(conn, sa_type, value):
178+
async def test_zero_dates(clickhouse_version, conn, sa_type, value):
179+
if clickhouse_version >= (20, 7):
180+
pytest.skip('Feature is dropped in 20.7')
179181
result = await conn.fetchval(
180182
sa.select([sa.func.cast(value, sa_type)])
181183
)

0 commit comments

Comments
 (0)