summaryrefslogtreecommitdiff
path: root/test/engine/test_execute.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-04-12 14:38:52 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-04-12 14:38:52 -0400
commit9273cdd6387bdf2182e595bdd5144a1792e9e1a4 (patch)
tree9913e1f2c844107064eb653787ba662d9b58a792 /test/engine/test_execute.py
parent3d66f727f56426592d70d5cf54bbcb891172b6f0 (diff)
downloadsqlalchemy-9273cdd6387bdf2182e595bdd5144a1792e9e1a4.tar.gz
- [bug] If conn.begin() fails when calling
"with engine.begin()", the newly acquired Connection is closed explicitly before propagating the exception onward normally.
Diffstat (limited to 'test/engine/test_execute.py')
-rw-r--r--test/engine/test_execute.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index 6bdbf4227..610f5e42b 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -358,6 +358,23 @@ class ConvenienceExecuteTest(fixtures.TablesTest):
testing.run_as_contextmanager(ctx, fn, 5, value=8)
self._assert_fn(5, value=8)
+ def test_transaction_engine_ctx_begin_fails(self):
+ engine = engines.testing_engine()
+ class MockConnection(Connection):
+ closed = False
+ def begin(self):
+ raise Exception("boom")
+
+ def close(self):
+ MockConnection.closed = True
+ engine._connection_cls = MockConnection
+ fn = self._trans_fn()
+ assert_raises(
+ Exception,
+ engine.begin
+ )
+ assert MockConnection.closed
+
def test_transaction_engine_ctx_rollback(self):
fn = self._trans_rollback_fn()
ctx = testing.db.begin()