Pytest cov does not generate any report

Viewed 14495

I'm trying to run a py.test cov for my program, but I still have an information: testFile.txt sCoverage.py warning: No data was collected. even when in the code are still non-tested functions (in my example function diff). Below is the example of the code on which I tested the command py.test --cov=testcov.py. I'm using python 2.7.9

def suma(x,y):
    z = x + y
    return z

def diff(x,y):
    return x-y

if __name__ == "__main__":
    a = suma(2,3)
    b = diff(7,5)
    print a
    print b

## ------------------------TESTS-----------------------------   
import pytest

def testSuma():
    assert suma(2,3) == 5

Can someone explain me, what am I doing wrong?

4 Answers

What worked well for me is:

py.test mytests/test_mytest.py --cov='.'

Specifying the path, '.' in this case, removes unwanted files from the coverage report.

Related