From af18c29f0b549eb72e6013348e4a0b938a20782f Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 16 Mar 2013 21:42:41 +0000 Subject: [PATCH] Fixed exception handling in disconnection test OperationalError is DatabaseError's subclass. --- tests/test_connection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 68de87ad..ca20868b 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -75,12 +75,14 @@ class ConnectionTests(unittest.TestCase): cur = conn.cursor() try: cur.execute("select pg_terminate_backend(pg_backend_pid())") - except psycopg2.DatabaseError, e: - # curiously in green mode we get a DatabaseError without pgcode - pass except psycopg2.OperationalError, e: if e.pgcode != psycopg2.errorcodes.ADMIN_SHUTDOWN: raise + except psycopg2.DatabaseError, e: + # curiously when disconnected in green mode we get a DatabaseError + # without pgcode. + if e.pgcode is not None: + raise self.assertEqual(conn.closed, 2) conn.close()