Fix IntegrityError management in tests