微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何删除python测试代码中的断言错误?

如何解决如何删除python测试代码中的断言错误?

这些是预测的测试方法

def test_get_prediction(input_params,output_params):
  exec_log.info("Testing started for prediction")
  response = aiservice.get_prediction(input_params)
  assert response['predicted_label'] != None
  test_insight(response)

def test_insight(response):

  if('featureImportance' in response['Insight']):
    data_table = response['Insight']['featureImportance']['data']
    assert len(data_table) > 0
  elif(response['Insight'] == 'nearestNeighbors'):
    data_dict = response['Insight']['nearestNeighbors']
    assert len(data_dict) > 0
  elif('modelCoefficients' in response['Insight']  ):
    data_table = response['Insight']['modelCoefficients ']['data']
    assert len(data_table) > 0

当我在 vs 代码中使用 pytest 进行测试时总是给出错误

================================== FAILURES ===================================
_______________ test_workflow[Classification: Credit Approval] ________________

caplog = <_pytest.logging.LogCaptureFixture object at 0x0000026B1EF15EE0>
test_name = 'Classification: Credit Approval'
test_params = [{'dataimport': {'expectedOutput': {'result': 'success'},'input': {'file_location': 'AWS','test_filename': 'credit_d...': 3,'yAxisLabel': 'Debt',...},'input': {'Age': 30,'BankCustomer': 
'g','Citizen': 'g','Creditscore': '1',...}}}]

  @pytest.mark.parametrize("test_name,test_params",TEST_ParaMS.items(),ids=list(TEST_ParaMS.keys()))
  def test_workflow(caplog,test_name,test_params):

    response = login()

    ai_service = create_ai_service()

    assert response == True
    assert len(ai_service) > 0
    problem_type = ''
    exec_log.info("testing started for " + test_name)
    for stage in test_params:
        for test_key,test_val in stage.items():
            if(test_key == 'dataimport'):
                test_upload_and_import_data(test_val['input'],test_val['expectedOutput'])
            elif(test_key == 'featureEngineering'):
                problem_type = test_feature_eng(test_val['input'],test_val['expectedOutput'])
            elif(test_key == 'training'):
                test_training(test_val['input'],test_val['expectedOutput'],problem_type)
            elif(test_key == "askAI"):
>               test_get_prediction(test_val['input'],test_val['expectedOutput'])

tests\test_pytest.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input_params = {'Age': '30.83','BankCustomer': 'g',...}
output_params = {'insight': 'featureImportance'}

@allure.step
def test_get_prediction(input_params,output_params):
    exec_log.info("Testing started for prediction")
    response = aiservice.get_prediction(input_params)
>   assert response['predicted_label'] != None
E   assert None != None

tests\test_pytest.py:210: AssertionError

这总是给出预测结果

{'statusCode': 400,'body': '{"predicted_label": null,"Message": "您尝试访问的网址不接受请求,请检查导航器提供的网址"}','headers': {'Content-Type': 'application/json','Access-Control-Allow-Origin': '*'}}

我需要 'statusCode': 'Completed','body': '{"predicted_label": "+" ........

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。