Skip to content

Commit 5080fcd

Browse files
Add option to run tests with other ClickHouse server than localhost
1 parent 15b6082 commit 5080fcd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

mcbackend/test_adapter_pymc.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .adapters.pymc import TraceBackend, find_data
1313
from .backends.clickhouse import ClickHouseBackend
14-
from .test_backend_clickhouse import HAS_REAL_DB
14+
from .test_backend_clickhouse import DB_KWARGS, HAS_REAL_DB
1515

1616
_log = logging.getLogger(__file__)
1717

@@ -57,9 +57,9 @@ class TestPyMCAdapter:
5757
def setup_method(self, method):
5858
"""Initializes a fresh database just for this test method."""
5959
self._db = "testing_" + hagelkorn.random()
60-
self._client_main = clickhouse_driver.Client("localhost")
60+
self._client_main = clickhouse_driver.Client(**DB_KWARGS)
6161
self._client_main.execute(f"CREATE DATABASE {self._db};")
62-
self._client = clickhouse_driver.Client("localhost", database=self._db)
62+
self._client = clickhouse_driver.Client(**DB_KWARGS, database=self._db)
6363
self.backend = ClickHouseBackend(self._client)
6464
return
6565

mcbackend/test_backend_clickhouse.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import logging
3+
import os
34
from datetime import datetime, timezone
45
from typing import Sequence, Tuple
56

@@ -21,7 +22,11 @@
2122
from mcbackend.test_utils import CheckBehavior, CheckPerformance, make_runmeta
2223

2324
try:
24-
client = clickhouse_driver.Client("localhost")
25+
DB_HOST = os.environ.get("CLICKHOUSE_HOST", "localhost")
26+
DB_PASS = os.environ.get("CLICKHOUSE_PASS", None)
27+
DB_PORT = os.environ.get("CLICKHOUSE_PORT", None)
28+
DB_KWARGS = dict(host=DB_HOST, port=DB_PORT, password=DB_PASS)
29+
client = clickhouse_driver.Client(**DB_KWARGS)
2530
client.execute("SHOW DATABASES;")
2631
HAS_REAL_DB = True
2732
except:
@@ -51,7 +56,7 @@ def fully_initialized(
5156

5257
@pytest.mark.skipif(
5358
condition=not HAS_REAL_DB,
54-
reason="Integration tests need a ClickHouse server on localhost:9000 without authentication.",
59+
reason="Integration tests need a ClickHouse server.",
5560
)
5661
class TestClickHouseBackendInitialization:
5762
"""This is separate because ``TestClickHouseBackend.setup_method`` depends on these things."""
@@ -63,12 +68,12 @@ def test_exceptions(self):
6368

6469
def test_backend_from_client_object(self):
6570
db = "testing_" + hagelkorn.random()
66-
_client_main = clickhouse_driver.Client("localhost")
71+
_client_main = clickhouse_driver.Client(**DB_KWARGS)
6772
_client_main.execute(f"CREATE DATABASE {db};")
6873

6974
try:
7075
# When created from a client object, all chains share the client
71-
backend = ClickHouseBackend(client=clickhouse_driver.Client("localhost", database=db))
76+
backend = ClickHouseBackend(client=clickhouse_driver.Client(**DB_KWARGS, database=db))
7277
assert callable(backend._client_fn)
7378
run = backend.init_run(make_runmeta())
7479
c1 = run.init_chain(0)
@@ -81,11 +86,11 @@ def test_backend_from_client_object(self):
8186

8287
def test_backend_from_client_function(self):
8388
db = "testing_" + hagelkorn.random()
84-
_client_main = clickhouse_driver.Client("localhost")
89+
_client_main = clickhouse_driver.Client(**DB_KWARGS)
8590
_client_main.execute(f"CREATE DATABASE {db};")
8691

8792
def client_fn():
88-
return clickhouse_driver.Client("localhost", database=db)
93+
return clickhouse_driver.Client(**DB_KWARGS, database=db)
8994

9095
try:
9196
# When created from a client function, each chain has its own client
@@ -108,7 +113,7 @@ def client_fn():
108113

109114
@pytest.mark.skipif(
110115
condition=not HAS_REAL_DB,
111-
reason="Integration tests need a ClickHouse server on localhost:9000 without authentication.",
116+
reason="Integration tests need a ClickHouse server.",
112117
)
113118
class TestClickHouseBackend(CheckBehavior, CheckPerformance):
114119
cls_backend = ClickHouseBackend
@@ -118,11 +123,11 @@ class TestClickHouseBackend(CheckBehavior, CheckPerformance):
118123
def setup_method(self, method):
119124
"""Initializes a fresh database just for this test method."""
120125
self._db = "testing_" + hagelkorn.random()
121-
self._client_main = clickhouse_driver.Client("localhost")
126+
self._client_main = clickhouse_driver.Client(**DB_KWARGS)
122127
self._client_main.execute(f"CREATE DATABASE {self._db};")
123-
self._client = clickhouse_driver.Client("localhost", database=self._db)
128+
self._client = clickhouse_driver.Client(**DB_KWARGS, database=self._db)
124129
self.backend = ClickHouseBackend(
125-
client_fn=lambda: clickhouse_driver.Client("localhost", database=self._db)
130+
client_fn=lambda: clickhouse_driver.Client(**DB_KWARGS, database=self._db)
126131
)
127132
return
128133

0 commit comments

Comments
 (0)