Pytest cov does not generate any report
Solution 1
You haven't said what all your files are named, so I'm not sure of the precise answer. But the argument to --cov
should be a module name, not a file name. So instead of py.test --cov=testcov.py
, you want py.test --cov=testcov
.
Solution 2
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.
Solution 3
py.test looks for functions that start with test_
. You should rename your test functions accordingly. To apply coverage you execute py.test --cov
. If you want a nice HTML report that also shows you which lines are not covered you can use py.test --cov --cov-report html
.
Ziva
Updated on July 21, 2022Comments
-
Ziva almost 2 years
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 commandpy.test --cov=testcov.py
. I'm usingpython 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?
-
BI Dude over 2 yearswhat if I want to use folder (SRC) instead of module