| 370 | |
| 371 | |
| 372 | def test_rollback(conn): |
| 373 | conn.pgconn.exec_(b"drop table if exists foo") |
| 374 | conn.pgconn.exec_(b"create table foo (id int primary key)") |
| 375 | conn.pgconn.exec_(b"begin") |
| 376 | assert conn.pgconn.transaction_status == pq.TransactionStatus.INTRANS |
| 377 | conn.pgconn.exec_(b"insert into foo values (1)") |
| 378 | conn.rollback() |
| 379 | assert conn.pgconn.transaction_status == pq.TransactionStatus.IDLE |
| 380 | res = conn.pgconn.exec_(b"select id from foo where id = 1") |
| 381 | assert res.ntuples == 0 |
| 382 | |
| 383 | conn.close() |
| 384 | with pytest.raises(psycopg.OperationalError): |
| 385 | conn.rollback() |
| 386 | |
| 387 | |
| 388 | def test_auto_transaction(conn): |