I have multiple python modules to be tested and I'm testing it using the tox file with the command "coverage run -m test_folder"
.
While testing, for few modules I'm getting lower test coverage. All the testcases have been written in the test file and it's working fine. But, when I checked coverage.html file, it is showing that function body is not executed. While debugging, the code is entering the function body.
for example: Below is the function fun_xyz.
import pandas as pd
def fun_xyz(input): #coverage is able to reach till this line only
ουτput = input[input.duplicated()] #coverage is unable to reach entire function body but while debugging, the code is entering function body and executing successfully
out_dict = {}
for k,v in output.groupby("Index"):
out_dict[k] = v["Code"].tolist()
return out_dict
Below is the testcase
def test_fun_xyz(): #this is executing successfully but didn't increase coverage percentage
df = pd.DataFrame([["A1", "101"],["A2", "102"],["A1", "101"] .["A3","103"],["A4","104"], ["A1","103"],["A1","103"], ["A2" , "102"]], columns = ["Index", "Code"])
output = fun_xyz(df)
assert output == {'A1': ['101', '103'], 'A2': ['102']}
test_fun_xyz()
I also added "#pragma = no cover" for some of the lines which are not included in the testcase. I'm trying to increase test coverage but overall percentage is not increasing because of the above mentioned issue.
May I please know how to resolve this issue?
coverage
) until you call the function. Please provide a minimal reproducible example so that we can see what you are actually doing.ουτput
vs.output
?