mardi 28 avril 2020

how to test two json file with pytest in python3.6

what would be the best way to test the case below with pytest with python3(3.6}+)?

json_data_one = {
   "id": 1,
   "status": True,
   "name": "Jhon"
}

json_data_two = {
   "id": 2,
   "status": False,
   "name": "Dave"
}
def foo(json_data_one, json_data_one):
    # not the best way to show this
    # but i want to loop through each json data then
    # show the result based on `status` is either `True` or `False`
    if json_data_one["status"] == True:
        return json_data_one
    elif json_data_one["status"] == False:
        return json_data_two

I am a bit lost on how to implement it but what i want to accomplish is check each json data, then if status == True return "name" == "John" but if status == False return "name" == "dave"

I believe parametrize could be used but i am having a hard time figuring it out.

Thank you.

Aucun commentaire:

Enregistrer un commentaire