#python #pytest #ddt #Json #DATA-DRIVEN

The article in continuation to the previous one, deals with parameterizing data to a given test from a json file

My json file looks like this: filename is myjson.json
Now I write a python module to fetch data from the json file: filename is readDataJ.py
import  pandas as pd

def getJSONData(fileName):    # create an empty list to store rows    rows = []
    # open the CSV file    # myJson = pd.read_json(fileName)    myJson=pd.read_json(fileName,orient="values")._get_values
    for row in myJson:        rows.append(row)
    return rows
 My script looks like this:
import pytest,unittest
from ddt import ddt, unpack, data
from readDataJ import getJSONData


@ddtclass Test_Class_1(unittest.TestCase):
    @data(*getJSONData("E:\Python-SeleniumFramework\pytest\dataDriven\json\\myjson.json"))
    # @unpack    def test_py_1(self,a):        for x in a:            print(x)
For details on pytest, ddt, pandas click the respective texts or search the blog.
Run the test
cmd > py.test -v -s test_dd.py

Output:








For more details refer to pandas

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Here is Mr Benjamin contact Email details,lfdsloans@outlook.com. / lfdsloans@lemeridianfds.com Or Whatsapp +1 989-394-3740 that helped me with loan of 90,000.00 Euros to startup my business and I'm very grateful,It was really hard on me here trying to make a way as a single mother things hasn't be easy with me but with the help of Le_Meridian put smile on my face as i watch my business growing stronger and expanding as well.I know you may surprise why me putting things like this here but i really have to express my gratitude so anyone seeking for financial help or going through hardship with there business or want to startup business project can see to this and have hope of getting out of the hardship..Thank You.

    ReplyDelete
  3. Your point about Python being adopted across almost every IT domain is absolutely correct. I've seen how adding automation testing to my Python skills helped me land a better role. For learners based in Electronic City who want a structured path with placement support, I strongly suggest software testing training and placement in electronic city bangalore. They cover real-time projects and help you build a strong portfolio. Thanks for sharing this detailed syllabus – it's a great reference for anyone planning their Python learning journey.

    ReplyDelete

Post a Comment

Popular Posts