23
23
24
24
def reserve_port ():
25
25
"""
26
- Generate a new port and add it to '_bound_ports '.
26
+ Generate a new port and add it to 'bound_ports '.
27
27
"""
28
28
29
- global bound_ports
30
29
port = port_for .select_random (exclude_ports = bound_ports )
31
30
bound_ports .add (port )
32
31
@@ -38,7 +37,6 @@ def release_port(port):
38
37
Free port provided by reserve_port().
39
38
"""
40
39
41
- global bound_ports
42
40
bound_ports .remove (port )
43
41
44
42
@@ -65,7 +63,7 @@ def generate_app_name():
65
63
"""
66
64
67
65
import uuid
68
- return '' . join ([ ' testgres-' , str (uuid .uuid4 ())] )
66
+ return 'testgres-{}' . format ( str (uuid .uuid4 ()))
69
67
70
68
71
69
def execute_utility (args , logfile ):
@@ -147,11 +145,7 @@ def get_pg_config():
147
145
NOTE: this fuction caches the result by default (see TestgresConfig).
148
146
"""
149
147
150
- global _pg_config_data
151
-
152
148
def cache_pg_config_data (cmd ):
153
- global _pg_config_data
154
-
155
149
# execute pg_config and get the output
156
150
out = subprocess .check_output ([cmd ]).decode ('utf-8' )
157
151
@@ -161,16 +155,19 @@ def cache_pg_config_data(cmd):
161
155
key , _ , value = line .partition ('=' )
162
156
data [key .strip ()] = value .strip ()
163
157
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
169
161
170
162
return data
171
163
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 :
174
171
return _pg_config_data
175
172
176
173
# try PG_CONFIG
0 commit comments