From: Daniele Varrazzo Date: Tue, 31 Aug 2021 14:42:07 +0000 (+0200) Subject: Fix tests retry if the failure leaves the connection in bad state X-Git-Tag: 3.0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8e895281151a95da607541515e07e164f5fac7b;p=thirdparty%2Fpsycopg.git Fix tests retry if the failure leaves the connection in bad state --- diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py index 67773c270..132fa1a93 100644 --- a/tests/test_server_cursor.py +++ b/tests/test_server_cursor.py @@ -96,6 +96,9 @@ def test_binary_cursor_text_override(conn): def test_close(conn, recwarn, retries): for retry in retries: with retry: + if conn.info.transaction_status == conn.TransactionStatus.INTRANS: + # connection dirty from previous failure + conn.execute("close foo") recwarn.clear() cur = conn.cursor("foo") cur.execute("select generate_series(1, 10) as bar") diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index 5814ed7f4..d240ac39d 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -98,6 +98,12 @@ async def test_binary_cursor_text_override(aconn): async def test_close(aconn, recwarn, retries): async for retry in retries: with retry: + if ( + aconn.info.transaction_status + == aconn.TransactionStatus.INTRANS + ): + # connection dirty from previous failure + await aconn.execute("close foo") recwarn.clear() cur = aconn.cursor("foo") await cur.execute("select generate_series(1, 10) as bar")