7575DEFAULT_XLOG_METHOD = "fetch"
7676
7777
78+ class TestgresConfig :
79+ cache_pg_config = True
80+ cache_initdb = True
81+
82+
7883class TestgresException (Exception ):
7984 """
8085 Base exception
@@ -1081,7 +1086,7 @@ def call_initdb(_data_dir):
10811086 raise InitNodeException (str (e ))
10821087
10831088 # Call initdb if we have custom params
1084- if initdb_params :
1089+ if initdb_params or not TestgresConfig . cache_initdb :
10851090 call_initdb (data_dir )
10861091 # Else we can use cached dir
10871092 else :
@@ -1190,25 +1195,31 @@ def get_pg_config():
11901195
11911196 global pg_config_data
11921197
1193- if not pg_config_data :
1194- pg_config_cmd = os .environ .get ("PG_CONFIG" ) or "pg_config"
1198+ if TestgresConfig .cache_pg_config and pg_config_data :
1199+ return pg_config_data
1200+
1201+ data = {}
1202+ pg_config_cmd = os .environ .get ("PG_CONFIG" ) or "pg_config"
1203+ out = six .StringIO (subprocess .check_output ([pg_config_cmd ],
1204+ universal_newlines = True ))
1205+ for line in out :
1206+ if line and "=" in line :
1207+ key , value = line .split ("=" , 1 )
1208+ data [key .strip ()] = value .strip ()
11951209
1196- out = six .StringIO (subprocess .check_output ([pg_config_cmd ],
1197- universal_newlines = True ))
1198- for line in out :
1199- if line and "=" in line :
1200- key , value = line .split ("=" , 1 )
1201- pg_config_data [key .strip ()] = value .strip ()
1210+ # Fetch version of PostgreSQL and save it as VERSION_NUM
1211+ version = data ["VERSION" ]
1212+ version = version .split (" " )[- 1 ] \
1213+ .partition ('devel' )[0 ] \
1214+ .partition ('beta' )[0 ] \
1215+ .partition ('rc' )[0 ]
1216+ data ["VERSION_NUM" ] = version
12021217
1203- # Fetch version of PostgreSQL and save it as VERSION_NUM
1204- version = pg_config_data ["VERSION" ]
1205- version = version .split (" " )[- 1 ] \
1206- .partition ('devel' )[0 ] \
1207- .partition ('beta' )[0 ] \
1208- .partition ('rc' )[0 ]
1209- pg_config_data ["VERSION_NUM" ] = version
1218+ if TestgresConfig .cache_pg_config :
1219+ pg_config_data .clear ()
1220+ pg_config_data .update (data )
12101221
1211- return pg_config_data
1222+ return data
12121223
12131224
12141225def get_new_node (name , base_dir = None , use_logging = False ):
@@ -1225,3 +1236,11 @@ def get_new_node(name, base_dir=None, use_logging=False):
12251236 """
12261237
12271238 return PostgresNode (name = name , base_dir = base_dir , use_logging = use_logging )
1239+
1240+
1241+ def configure_testgres (** options ):
1242+ '''
1243+ Configure testgres. Look for TestgresConfig to check what can be changed.
1244+ '''
1245+ for key , option in options .items ():
1246+ setattr (TestgresConfig , key , option )
0 commit comments