I have to read a CSV file and for each combination in each row need to run some methods.I would like to see each row as a test case. Is it possible to send row as a param - pytest parameterize my test case? Can you please give me some idea on how to do that?
Here is the pseudo code:
class test_mytest:
def test_rows:
for row in csvreader:
run_method(row)
for onecol in row:
run_method2(onecol)
I have tried reading the pytest
documentation but it was not clear for me.
Here is what I am doing for using generate_tests hook for row as a param.I would like to know how to do same for the inner for loop function-this inner loop also should be collected as a test case
def pytest_generate_tests(metafunc):
read_csvrows()
for funcargs in metafunc.cls.params[metafunc.function.__name__]:
# schedule a new test function run with applied **funcargs
metafunc.addcall(funcargs=funcargs)
class TestClass:
params = {
'test_rows': rows,
}
def test_rows:
run_method(row)
for onecol in row:
test_method2(onecol)
Now, I need to generate reports for the -for loop calling test_method2 (it is parameterized method for list of elements in the column in each row of csv file). Pytest needs to collect those as test case as well.
Appreciate your help.Thanks