From: Daniele Varrazzo Date: Sun, 1 Aug 2021 23:17:52 +0000 (+0200) Subject: Add test to verify errors in row factories are handled ok X-Git-Tag: 3.0.dev2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0a400aa86e7fed61bfc33b2e0a20648f9316717;p=thirdparty%2Fpsycopg.git Add test to verify errors in row factories are handled ok --- diff --git a/tests/test_cursor.py b/tests/test_cursor.py index b88080292..e1faa6a56 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -304,6 +304,26 @@ def test_row_factory(conn): assert cur.fetchone() == {"y": "y", "z": "z"} +def test_bad_row_factory(conn): + def broken_factory(cur): + 1 / 0 + + cur = conn.cursor(row_factory=broken_factory) + with pytest.raises(ZeroDivisionError): + cur.execute("select 1") + + def broken_maker(cur): + def make_row(seq): + 1 / 0 + + return make_row + + cur = conn.cursor(row_factory=broken_maker) + cur.execute("select 1") + with pytest.raises(ZeroDivisionError): + cur.fetchone() + + def test_scroll(conn): cur = conn.cursor() with pytest.raises(psycopg.ProgrammingError): diff --git a/tests/test_cursor_async.py b/tests/test_cursor_async.py index 1e0ec046d..b29070f02 100644 --- a/tests/test_cursor_async.py +++ b/tests/test_cursor_async.py @@ -310,6 +310,26 @@ async def test_row_factory(aconn): assert await cur.fetchone() == {"y": "y", "z": "z"} +async def test_bad_row_factory(aconn): + def broken_factory(cur): + 1 / 0 + + cur = aconn.cursor(row_factory=broken_factory) + with pytest.raises(ZeroDivisionError): + await cur.execute("select 1") + + def broken_maker(cur): + def make_row(seq): + 1 / 0 + + return make_row + + cur = aconn.cursor(row_factory=broken_maker) + await cur.execute("select 1") + with pytest.raises(ZeroDivisionError): + await cur.fetchone() + + async def test_scroll(aconn): cur = aconn.cursor() with pytest.raises(psycopg.ProgrammingError):