diff options
author | Rafi Shamim <rafi@cockroachlabs.com> | 2020-07-07 18:48:44 -0400 |
---|---|---|
committer | Rafi Shamim <rafi@cockroachlabs.com> | 2020-07-07 18:48:44 -0400 |
commit | a61f30b2d26af134c89e040703d94239ea9a0bf6 (patch) | |
tree | 54818d49c38eba5a8c32b271a4d193a619dd1fec | |
parent | 779a1370ceeac130de07edc0510f2c55846be1bd (diff) | |
download | psycopg2-a61f30b2d26af134c89e040703d94239ea9a0bf6.tar.gz |
Handle failure in setup of IsolationLevelsTestCase
If the CREATE TABLE statement fails, the setup would fail
without committing or rolling back the active transaction, so the
transaction would hold onto its resources indefinitely.
Normally, the transaction would be closed when the connection is closed
in the `tearDown` function. However, `tearDown` is not called if there
was an error during `setUp` ([as specified by the `unittest` docs](https://docs.python.org/3/library/unittest.html#unittest.TestCase.tearDown)), so
we need to handle this case specially.
-rwxr-xr-x | tests/test_connection.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tests/test_connection.py b/tests/test_connection.py index 8236801..af2c3c4 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -567,9 +567,11 @@ class IsolationLevelsTestCase(ConnectingTestCase): cur.execute("drop table isolevel;") except psycopg2.ProgrammingError: conn.rollback() - cur.execute("create table isolevel (id integer);") - conn.commit() - conn.close() + try: + cur.execute("create table isolevel (id integer);") + conn.commit() + finally: + conn.close() def test_isolation_level(self): conn = self.connect() |