2323
2424def reserve_port ():
2525 """
26- Generate a new port and add it to '_bound_ports '.
26+ Generate a new port and add it to 'bound_ports '.
2727 """
2828
29- global bound_ports
3029 port = port_for .select_random (exclude_ports = bound_ports )
3130 bound_ports .add (port )
3231
@@ -38,7 +37,6 @@ def release_port(port):
3837 Free port provided by reserve_port().
3938 """
4039
41- global bound_ports
4240 bound_ports .remove (port )
4341
4442
@@ -65,7 +63,7 @@ def generate_app_name():
6563 """
6664
6765 import uuid
68- return '' . join ([ ' testgres-' , str (uuid .uuid4 ())] )
66+ return 'testgres-{}' . format ( str (uuid .uuid4 ()))
6967
7068
7169def execute_utility (args , logfile ):
@@ -147,11 +145,7 @@ def get_pg_config():
147145 NOTE: this fuction caches the result by default (see TestgresConfig).
148146 """
149147
150- global _pg_config_data
151-
152148 def cache_pg_config_data (cmd ):
153- global _pg_config_data
154-
155149 # execute pg_config and get the output
156150 out = subprocess .check_output ([cmd ]).decode ('utf-8' )
157151
@@ -161,16 +155,19 @@ def cache_pg_config_data(cmd):
161155 key , _ , value = line .partition ('=' )
162156 data [key .strip ()] = value .strip ()
163157
164- _pg_config_data .clear ()
165-
166- # cache data, if necessary
167- if TestgresConfig .cache_pg_config :
168- _pg_config_data = data
158+ # cache data
159+ global _pg_config_data
160+ _pg_config_data = data
169161
170162 return data
171163
172- # return cached data, if allowed to
173- if TestgresConfig .cache_pg_config and _pg_config_data :
164+ # drop cache if asked to
165+ if not TestgresConfig .cache_pg_config :
166+ global _pg_config_data
167+ _pg_config_data = {}
168+
169+ # return cached data
170+ if _pg_config_data :
174171 return _pg_config_data
175172
176173 # try PG_CONFIG
0 commit comments