forked from pool/python-pytest-server-fixtures
- Fix compatibikity with with Psycopg 2.9 * pytest-plugins-pr186-fix-psycopg29.patch * gh#man-group/pytest-plugins#186 OBS-URL: https://build.opensuse.org/request/show/925874 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:pytest/python-pytest-server-fixtures?expand=0&rev=9
44 lines
1.9 KiB
Diff
44 lines
1.9 KiB
Diff
From 291995b3cfe60a5b30d5c6e1f3279ea40d35c7bb Mon Sep 17 00:00:00 2001
|
|
From: Ben Greiner <code@bnavigator.de>
|
|
Date: Sun, 17 Oct 2021 18:57:06 +0200
|
|
Subject: [PATCH] Don't use context manager for CREATE DATABASE
|
|
|
|
Psycopg 2.9 uses transaction blocks withing context managers,
|
|
which is not allowed for CREATE DATABASE
|
|
https://github.com/psycopg/psycopg2/issues/941
|
|
---
|
|
.../pytest_server_fixtures/postgres.py | 12 ++++++++----
|
|
1 file changed, 8 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/pytest-server-fixtures/pytest_server_fixtures/postgres.py b/pytest-server-fixtures/pytest_server_fixtures/postgres.py
|
|
index 7c6ea33..aeab36a 100644
|
|
--- a/pytest-server-fixtures/pytest_server_fixtures/postgres.py
|
|
+++ b/pytest-server-fixtures/pytest_server_fixtures/postgres.py
|
|
@@ -103,18 +103,22 @@ def run_cmd(self):
|
|
|
|
def check_server_up(self):
|
|
from psycopg2 import OperationalError
|
|
+ conn = None
|
|
try:
|
|
print("Connecting to Postgres at localhost:{}".format(self.port))
|
|
- with self.connect('postgres') as conn:
|
|
- conn.set_session(autocommit=True)
|
|
- with conn.cursor() as cursor:
|
|
- cursor.execute("CREATE DATABASE " + self.database_name)
|
|
+ conn = self.connect('postgres')
|
|
+ conn.set_session(autocommit=True)
|
|
+ with conn.cursor() as cursor:
|
|
+ cursor.execute("CREATE DATABASE " + self.database_name)
|
|
self.connection = self.connect(self.database_name)
|
|
with open(self.workspace / 'db' / 'postmaster.pid', 'r') as f:
|
|
self.pid = int(f.readline().rstrip())
|
|
return True
|
|
except OperationalError as e:
|
|
print("Could not connect to test postgres: {}".format(e))
|
|
+ finally:
|
|
+ if conn:
|
|
+ conn.close()
|
|
return False
|
|
|
|
def connect(self, database=None):
|