0

Suppose I have a python project with tests written in tests/

If I run python -m pytest --cov tests/ that seems to give me code coverage for all files in tests/. If I run python -m pytest --cov=. tests/ that seems to give me coverage results for all files in the project.

When we want code coverage, are we asking for coverage in terms of what the tests cover (so my first CLI should be the one to run) or should results be based on src/ files?

dataviews
  • 2,466
  • 7
  • 31
  • 64
  • Point to src directory: `python -m pytest --cov=src tests/`. Is that what you are looking for ? – Maurice Meyer Aug 11 '22 at 14:58
  • @MauriceMeyer if I point to source, my coverage results show less than 95% for files in src/ but 99-100% for files in tests/. Should i be looking at results from tests/ ? – dataviews Aug 11 '22 at 15:00

1 Answers1

1

Probably you are missing the flag term-missing, that's what I am using and there is no coverage for ./tests shown:

set PYTHONPATH=<fullpath_to>src
pytest --self-contained-html -s --durations=0 --cov-report html:cov_html --cov-report term-missing --cov=src tests/unittests -vv
Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47