async def test_delete_roles(app, role_type, rolename, response_type, response, caplog):
    """Test raising errors and info when deleting roles"""
    caplog.set_level(logging.INFO)
    db = app.db

    if response_type == 'info':
        # add the role to db
        test_role = orm.Role(name=rolename)
        db.add(test_role)
        db.commit()
        check_role = orm.Role.find(db, rolename)
        assert check_role is not None
        # check the role is deleted and info logged
        roles.delete_role(db, rolename)
        if response:
            assert response in caplog.text
        check_role = orm.Role.find(db, rolename)
        assert check_role is None

    elif response_type == 'error':
        with pytest.raises(response):
            roles.delete_role(db, rolename)
Test raising errors and info when deleting roles
jupyterhub/tests/test_roles.py