4242# PYO_TEST_DRIVER_MODE: python-oracledb mode (thick or thin) to use
4343# PYO_TEST_EXTERNAL_USER: user for testing external authentication
4444# PYO_TEST_EDITION_NAME: name of edition for editioning tests
45+ # PYO_TEST_PLUGINS: list of plugins to import before running tests
4546#
4647# PYO_TEST_CONNECT_STRING can be set to an Easy Connect string, or a
4748# Net Service Name from a tnsnames.ora file or external naming service,
6566# -----------------------------------------------------------------------------
6667
6768import getpass
69+ import importlib
6870import os
6971import secrets
7072import sys
8587PARAMETERS = {}
8688
8789
90+ def _initialize ():
91+ """
92+ 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.
95+ """
96+ if not get_is_thin ():
97+ oracledb .init_oracle_client ()
98+ plugin_names = os .environ .get ("PYO_TEST_PLUGINS" )
99+ if plugin_names is not None :
100+ for name in plugin_names .split ("," ):
101+ module_name = f"oracledb.plugins.{ name } "
102+ print ("importing module" , module_name )
103+ importlib .import_module (module_name )
104+ get_connection ()
105+
106+
88107def get_value (name , label , default_value = None , password = False ):
89108 try :
90109 return PARAMETERS [name ]
91110 except KeyError :
92111 pass
112+ requires_initialization = len (PARAMETERS ) == 0
93113 env_name = "PYO_TEST_" + name
94114 value = os .environ .get (env_name )
95115 if value is None :
@@ -103,12 +123,12 @@ def get_value(name, label, default_value=None, password=False):
103123 if not value :
104124 value = default_value
105125 PARAMETERS [name ] = value
126+ if requires_initialization :
127+ _initialize ()
106128 return value
107129
108130
109131def get_admin_connection (use_async = False ):
110- if not get_is_thin () and oracledb .is_thin_mode ():
111- oracledb .init_oracle_client ()
112132 admin_user = get_value ("ADMIN_USER" , "Administrative user" , "admin" )
113133 admin_password = get_value (
114134 "ADMIN_PASSWORD" , f"Password for { admin_user } " , password = True
@@ -209,7 +229,6 @@ def get_client_version():
209229 if get_is_thin ():
210230 value = (23 , 7 )
211231 else :
212- oracledb .init_oracle_client ()
213232 value = oracledb .clientversion ()[:2 ]
214233 PARAMETERS [name ] = value
215234 return value
@@ -228,8 +247,6 @@ def get_connect_params():
228247
229248
230249def get_connection (dsn = None , use_async = False , ** kwargs ):
231- if not get_is_thin () and oracledb .is_thin_mode ():
232- oracledb .init_oracle_client ()
233250 if dsn is None :
234251 dsn = get_connect_string ()
235252 method = oracledb .connect_async if use_async else oracledb .connect
@@ -445,6 +462,7 @@ def run_sql_script(conn, script_name, **kwargs):
445462
446463
447464def run_test_cases ():
465+ get_is_thin ()
448466 unittest .main (testRunner = unittest .TextTestRunner (verbosity = 2 ))
449467
450468
@@ -664,8 +682,6 @@ def is_on_oracle_cloud(self, connection=None):
664682 return is_on_oracle_cloud (connection )
665683
666684 def setUp (self ):
667- if not get_is_thin () and oracledb .is_thin_mode ():
668- oracledb .init_oracle_client ()
669685 if self .requires_connection :
670686 self .conn = get_connection ()
671687 self .cursor = self .conn .cursor ()
0 commit comments