def tester():
     self.assertEqual(TRN._contexts_entered, 1)
     with TRN:
         self.assertEqual(TRN._contexts_entered, 2)
         sql = """SELECT EXISTS(
                 SELECT * FROM labcontrol.test_table WHERE int_column=%s)"""
         TRN.add(sql, [2])
         self.assertTrue(TRN.execute_fetchlast())
     self.assertEqual(TRN._contexts_entered, 1)
    def test_execute_fetchlast(self):
        with TRN:
            sql = """INSERT INTO labcontrol.test_table (str_column, int_column)
                     VALUES (%s, %s) RETURNING str_column, int_column"""
            args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
            TRN.add(sql, args, many=True)

            sql = """SELECT EXISTS(
                        SELECT * FROM labcontrol.test_table WHERE int_column=%s)"""
            TRN.add(sql, [2])
            self.assertTrue(TRN.execute_fetchlast())

            sql = """SELECT str_column FROM labcontrol.test_table
                     WHERE int_column = %s"""
            TRN.add(sql, [2])
            self.assertEqual(TRN.execute_fetchlast(), 'insert2')

            TRN.add(sql, [4])
            self.assertIsNone(TRN.execute_fetchlast())