def test_dirty_protection(self): Session.flush() # should not throw an exception serialized_call(lambda: None)() Session.flush() # nothing happened, no exception serialized_call(add_something)() self.assertRaises(DirtyReadOnlySession, lambda: Session.flush)