Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

json - How to remove the assertion error in python test code?

These are the testing methods for prediction

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

When I test using pytest in the vs code always gives error as

================================== 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'])

testsest_pytest.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input_params = {'Age': '30.83', 'BankCustomer': 'g', 'Citizen': 'g', 'CreditScore': '1', ...}
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

testsest_pytest.py:210: AssertionError

This always gives the prediction result as

{'statusCode': 400, 'body': '{"predicted_label": null, "Message": "The url you are trying to access is not accepting requests, please check the url provided by Navigator"}', 'headers': {'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*'}}

I need 'statusCode': 'Completed','body': '{"predicted_label": "+" ........


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...