11import asyncio
22from datetime import datetime
33from decimal import Decimal
4+ import os
45
56import clickhouse_sqlalchemy
67import 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
2850async def pool (dsn ):
2951 async with aiochsa .create_pool (dsn ) as pool :
0 commit comments