mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-16 17:10:32 +03:00
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.
This commit is contained in:
parent
779a1370ce
commit
a61f30b2d2
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user