0

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?

6
  • 1
    Python doesn't have function declarations, only definitions. But if you are talking about the body of a function, that doesn't get executed (and thus is "invisible" to coverage) until you call the function. Please provide a minimal reproducible example so that we can see what you are actually doing.
    – chepner
    Commented Jun 18 at 14:32
  • @chepner Thanks for your quick response. I have updated the query. Could you please check?
    – Nelson
    Commented Jun 18 at 15:24
  • This is not a minimal reproducible example (please follow the link). We cannot copy this, execute it, and reproduce what you are seeing.
    – chepner
    Commented Jun 18 at 15:32
  • Thanks @chepner. I have updated my query. Could you please check?
    – Nelson
    Commented Jun 18 at 16:48
  • What is going on with the variable name ουτput vs. output?
    – Mark
    Commented Jun 19 at 4:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.