Skip to content

Commit ad3aef7

Browse files
committed
Remove static variables from clickhouse.
1 parent 7a06617 commit ad3aef7

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

clickhouse/testcontainers/clickhouse/__init__.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,21 @@ class ClickHouseContainer(DbContainer):
3939
... client.execute("select 'working'")
4040
[('working',)]
4141
"""
42-
43-
CLICKHOUSE_USER = os.environ.get("CLICKHOUSE_USER", "test")
44-
CLICKHOUSE_PASSWORD = os.environ.get("CLICKHOUSE_PASSWORD", "test")
45-
CLICKHOUSE_DB = os.environ.get("CLICKHOUSE_DB", "test")
46-
4742
def __init__(
4843
self,
4944
image: str = "clickhouse/clickhouse-server:latest",
5045
port: int = 9000,
51-
user: Optional[str] = None,
46+
username: Optional[str] = None,
5247
password: Optional[str] = None,
53-
dbname: Optional[str] = None
48+
dbname: Optional[str] = None,
49+
user: None = None,
5450
) -> None:
5551
super().__init__(image=image)
56-
57-
self.CLICKHOUSE_USER = user or self.CLICKHOUSE_USER
58-
self.CLICKHOUSE_PASSWORD = password or self.CLICKHOUSE_PASSWORD
59-
self.CLICKHOUSE_DB = dbname or self.CLICKHOUSE_DB
52+
if user:
53+
raise ValueError("use `username` instead")
54+
self.username = username or os.environ.get("CLICKHOUSE_USER", "test")
55+
self.password = password or os.environ.get("CLICKHOUSE_PASSWORD", "test")
56+
self.dbname = dbname or self.os.environ.get("CLICKHOUSE_DB", "test")
6057
self.port_to_expose = port
6158
self.with_exposed_ports(self.port_to_expose)
6259

@@ -66,16 +63,16 @@ def _connect(self) -> None:
6663
client.execute("SELECT version()")
6764

6865
def _configure(self) -> None:
69-
self.with_env("CLICKHOUSE_USER", self.CLICKHOUSE_USER)
70-
self.with_env("CLICKHOUSE_PASSWORD", self.CLICKHOUSE_PASSWORD)
71-
self.with_env("CLICKHOUSE_DB", self.CLICKHOUSE_DB)
66+
self.with_env("CLICKHOUSE_USER", self.username)
67+
self.with_env("CLICKHOUSE_PASSWORD", self.password)
68+
self.with_env("CLICKHOUSE_DB", self.dbname)
7269

7370
def get_connection_url(self, host: Optional[str] = None) -> str:
7471
return self._create_connection_url(
7572
dialect="clickhouse",
76-
username=self.CLICKHOUSE_USER,
77-
password=self.CLICKHOUSE_PASSWORD,
78-
db_name=self.CLICKHOUSE_DB,
73+
username=self.username,
74+
password=self.password,
75+
db_name=self.dbname,
7976
host=host,
8077
port=self.port_to_expose,
8178
)

0 commit comments

Comments
 (0)