What is pytest result mean?
Question:
I’m learning about testing in Python, and now I’m using pytest-cov.
I try to run this command:
pytest --cov=myProj tests/ --cov-report term-missing
after the testing done I got the report like this:
----------- coverage: platform linux, python 3.6.7-final-0 -----------
Name Stmts Miss Cover Missing
----------------------------------------------------------------------------------------------
myProject/__init__.py 0 0 100%
myProject/alert.py 14 14 0% 1-21
myProject/api/__init__.py 1 0 100%
myProject/api/spaces/__init__.py 0 0 100%
myProject/api/spaces/admin.py 279 179 36% 154-223, 312-335, 351-398, 422-432, 505-515, 534-565, 591-697
myProject/api/spaces/global.py 89 66 26% 35-43, 47-69, 72-92, 96-124
myProject/api/spaces/inventory.py 79 79 0% 1-119
myProject/api/spaces/keyword.py 134 110 18% 33-42, 46-68, 72-93, 101-112, 116-134, 138-165, 168-190
A few things that make me still confuse about the report that I still didn’t find it in the documentation are about:
what is
Stmts, Miss, Cover, and Missing, is that if the result on Cover doesn’t 100% it means my code still bad or what..?
Answers:
Stmts
refers to the number of statements in your code.
Miss
refers to the number of statements that have not been run.
Cover
is test coverage, or (Stmts - Miss) / (Stmts) * 100
.
Missing
contains the line numbers of the Miss
statements.
If coverage is not 100%, that means that there are parts of your code that your tests do not cover, for example:
def f(a, b):
if a > 0:
return a
elif a == 0:
return 0
else:
return b
def test_f():
assert f(10, 10)
The above test will only ever enter the a > 0
branch and will therefore have a test coverage of 33%.
High coverage is not always good (because just covering code doesn’t mean that all cases are tested adequately), but low coverage is often bad (because that means your tests are not even touching parts of your code).
- Stmts – means the total lines of code you have in a specific file.
- Miss – total number of lines that are not covered by unittest.
- Cover – percentage of all line of code that are covered by unittest.
- Missing – lines of codes that are not covered.
I’m learning about testing in Python, and now I’m using pytest-cov.
I try to run this command:
pytest --cov=myProj tests/ --cov-report term-missing
after the testing done I got the report like this:
----------- coverage: platform linux, python 3.6.7-final-0 -----------
Name Stmts Miss Cover Missing
----------------------------------------------------------------------------------------------
myProject/__init__.py 0 0 100%
myProject/alert.py 14 14 0% 1-21
myProject/api/__init__.py 1 0 100%
myProject/api/spaces/__init__.py 0 0 100%
myProject/api/spaces/admin.py 279 179 36% 154-223, 312-335, 351-398, 422-432, 505-515, 534-565, 591-697
myProject/api/spaces/global.py 89 66 26% 35-43, 47-69, 72-92, 96-124
myProject/api/spaces/inventory.py 79 79 0% 1-119
myProject/api/spaces/keyword.py 134 110 18% 33-42, 46-68, 72-93, 101-112, 116-134, 138-165, 168-190
A few things that make me still confuse about the report that I still didn’t find it in the documentation are about:
what is
Stmts, Miss, Cover, and Missing, is that if the result on Cover doesn’t 100% it means my code still bad or what..?
Stmts
refers to the number of statements in your code.
Miss
refers to the number of statements that have not been run.
Cover
is test coverage, or (Stmts - Miss) / (Stmts) * 100
.
Missing
contains the line numbers of the Miss
statements.
If coverage is not 100%, that means that there are parts of your code that your tests do not cover, for example:
def f(a, b):
if a > 0:
return a
elif a == 0:
return 0
else:
return b
def test_f():
assert f(10, 10)
The above test will only ever enter the a > 0
branch and will therefore have a test coverage of 33%.
High coverage is not always good (because just covering code doesn’t mean that all cases are tested adequately), but low coverage is often bad (because that means your tests are not even touching parts of your code).
- Stmts – means the total lines of code you have in a specific file.
- Miss – total number of lines that are not covered by unittest.
- Cover – percentage of all line of code that are covered by unittest.
- Missing – lines of codes that are not covered.