What is pytest result mean?
Asked Answered
T

2

6

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..?

Tyrocidine answered 22/3, 2019 at 5:3 Comment(0)
T
11

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).

Thiosinamine answered 22/3, 2019 at 5:9 Comment(0)
S
2
  • 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.
Starlin answered 22/3, 2019 at 5:13 Comment(1)
I'm still don't got it about Stmts, because at my report that in my real project, I have 54 lines (whitout lines break) in my file and 26 lines in my test file (also without line break), but in my report the Stmts it showing 28.Tyrocidine

© 2022 - 2024 — McMap. All rights reserved.