Skip to content

Commit 2f575ab

Browse files
Change the location where initialization takes place in order to ensure
that test suites that call init_oracle_client() themselves will function as expected.
1 parent 1a072f7 commit 2f575ab

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/test_env.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@
9090
def _initialize():
9191
"""
9292
Performs initialization of the test environment. This ensures the desired
93-
mode is set, imports any required plugins and establishes a test
94-
connection to ensure that the supplied credentials are correct.
93+
mode is set and imports any required plugins.
9594
"""
96-
if not get_is_thin():
95+
if PARAMETERS.get("INITIALIZED"):
96+
return
97+
if not get_is_thin() and oracledb.is_thin_mode():
9798
oracledb.init_oracle_client()
9899
oracledb.defaults.thick_mode_dsn_passthrough = False
99100
plugin_names = os.environ.get("PYO_TEST_PLUGINS")
@@ -102,14 +103,14 @@ def _initialize():
102103
module_name = f"oracledb.plugins.{name}"
103104
print("importing module", module_name)
104105
importlib.import_module(module_name)
106+
PARAMETERS["INITIALIZED"] = True
105107

106108

107109
def get_value(name, label, default_value=None, password=False):
108110
try:
109111
return PARAMETERS[name]
110112
except KeyError:
111113
pass
112-
requires_initialization = len(PARAMETERS) == 0
113114
env_name = "PYO_TEST_" + name
114115
value = os.environ.get(env_name)
115116
if value is None:
@@ -123,12 +124,11 @@ def get_value(name, label, default_value=None, password=False):
123124
if not value:
124125
value = default_value
125126
PARAMETERS[name] = value
126-
if requires_initialization:
127-
_initialize()
128127
return value
129128

130129

131130
def get_admin_connection(use_async=False):
131+
_initialize()
132132
admin_user = get_value("ADMIN_USER", "Administrative user", "admin")
133133
admin_password = get_value(
134134
"ADMIN_PASSWORD", f"Password for {admin_user}", password=True
@@ -229,6 +229,7 @@ def get_client_version():
229229
if get_is_thin():
230230
value = (23, 7)
231231
else:
232+
_initialize()
232233
value = oracledb.clientversion()[:2]
233234
PARAMETERS[name] = value
234235
return value
@@ -247,6 +248,7 @@ def get_connect_params():
247248

248249

249250
def get_connection(dsn=None, use_async=False, **kwargs):
251+
_initialize()
250252
if dsn is None:
251253
dsn = get_connect_string()
252254
method = oracledb.connect_async if use_async else oracledb.connect
@@ -316,6 +318,7 @@ def get_main_user():
316318

317319

318320
def get_pool(use_async=False, **kwargs):
321+
_initialize()
319322
method = oracledb.create_pool_async if use_async else oracledb.create_pool
320323
return method(dsn=get_connect_string(), params=get_pool_params(), **kwargs)
321324

0 commit comments

Comments
 (0)