mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
@ -207,6 +207,12 @@ class Connection(_mysql.connection):
|
||||
self.autocommit(autocommit)
|
||||
self.messages = []
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.close()
|
||||
|
||||
def autocommit(self, on):
|
||||
on = bool(on)
|
||||
if self.get_autocommit() != on:
|
||||
|
@ -99,3 +99,8 @@ class CoreAPI(unittest.TestCase):
|
||||
|
||||
def test_fileno(self):
|
||||
self.assertGreaterEqual(self.conn.fileno(), 0)
|
||||
|
||||
def test_context_manager(self):
|
||||
with connection_factory() as conn:
|
||||
self.assertFalse(conn.closed)
|
||||
self.assertTrue(conn.closed)
|
||||
|
Reference in New Issue
Block a user