def test_session_context_as_transaction(self): """ Demonstrate using the context of a session transaction """ session = TestSession() p = Project( name="A Project", createdBy="me", dateCreated=datetime.datetime.today(), currency="UKP", agroYearBegins=calendar.month_name[5], ) self.assertEqual(session.query(Project).count(), 0) with session.begin(subtransactions=True): session.add(p) self.assertEqual(len(session.new), 1) self.assertIn(p, session) # No need for explicit commit self.assertEqual(session.query(Project).count(), 1)