File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
pytest-server-fixtures/pytest_server_fixtures Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -103,18 +103,22 @@ def run_cmd(self):
103103
104104 def check_server_up (self ):
105105 from psycopg2 import OperationalError
106+ conn = None
106107 try :
107108 print ("Connecting to Postgres at localhost:{}" .format (self .port ))
108- with self .connect ('postgres' ) as conn :
109- conn .set_session (autocommit = True )
110- with conn .cursor () as cursor :
111- cursor .execute ("CREATE DATABASE " + self .database_name )
109+ conn = self .connect ('postgres' )
110+ conn .set_session (autocommit = True )
111+ with conn .cursor () as cursor :
112+ cursor .execute ("CREATE DATABASE " + self .database_name )
112113 self .connection = self .connect (self .database_name )
113114 with open (self .workspace / 'db' / 'postmaster.pid' , 'r' ) as f :
114115 self .pid = int (f .readline ().rstrip ())
115116 return True
116117 except OperationalError as e :
117118 print ("Could not connect to test postgres: {}" .format (e ))
119+ finally :
120+ if conn :
121+ conn .close ()
118122 return False
119123
120124 def connect (self , database = None ):
You can’t perform that action at this time.
0 commit comments