MCPcopy
hub / github.com/psycopg/psycopg / test_auto_transaction

Function test_auto_transaction

tests/test_connection_async.py:384–398  ·  view source on GitHub ↗
(aconn)

Source from the content-addressed store, hash-verified

382
383
384async def test_auto_transaction(aconn):
385 aconn.pgconn.exec_(b"drop table if exists foo")
386 aconn.pgconn.exec_(b"create table foo (id int primary key)")
387
388 cur = aconn.cursor()
389 assert aconn.pgconn.transaction_status == pq.TransactionStatus.IDLE
390
391 await cur.execute("insert into foo values (1)")
392 assert aconn.pgconn.transaction_status == pq.TransactionStatus.INTRANS
393
394 await aconn.commit()
395 assert aconn.pgconn.transaction_status == pq.TransactionStatus.IDLE
396 await cur.execute("select * from foo")
397 assert await cur.fetchone() == (1,)
398 assert aconn.pgconn.transaction_status == pq.TransactionStatus.INTRANS
399
400
401async def test_auto_transaction_fail(aconn):

Callers

nothing calls this directly

Calls 5

exec_Method · 0.45
cursorMethod · 0.45
executeMethod · 0.45
commitMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected