#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
Run the test
cmd > py.test -v -s test_dd.py
Output:
For more details refer to pandas
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 rowsMy 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
Good work mate
ReplyDeleteGood blog,Great experience for me by reading this article.
ReplyDeletecore java training in chennai
core java classes
core javaTraining in Tambaram
c c++ courses in chennai
C Language Training
javascript training in chennai
Appium Training in Chennai
JMeter Training in Chennai
I have been continuously reading all your post. Keep doing more. Waiting for more.
ReplyDeleteSpoken English Classes in Chennai
Spoken English Class in Chennai
Spoken English in Chennai
IELTS Training in Chennai
IELTS Chennai
Best English Speaking Classes in Mumbai
Spoken English Classes in Mumbai
IELTS Mumbai
IELTS Center in Mumbai
IELTS Coaching in Anna Nagar
This comment has been removed by the author.
ReplyDeleteHere 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.
ReplyDeleteOinsuFspis_so Lisa Williams https://wakelet.com/wake/BxfHWPNuMNhAEXfjFO9MV
ReplyDeletegalestiogold