pytest-cov
pytest-cov copied to clipboard
Unable to change dir for test coverage calculation
pytest-cov not respecting the --cov flag
Expected vs actual result
I am expecting that the --cov flag directs which directory's(package's) coverage is to be calculated. I only want to calculate coverage for src.blueprints package of mine, whereas pytest-cov gives me the coverage for my src directory even after explicitly changing the --cov parameter to src.blueprints or src/blueprints
pytest -c config/pyproject.toml --cov src/blueprints
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.9.4, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /home/onlinejudge95/.pyenv/versions/3.9.4/envs/email/bin/python3.9
cachedir: .pytest_cache
rootdir: /home/onlinejudge95/workspace/github/email_service/src/blueprints, configfile: ../../config/pyproject.toml
plugins: cov-2.12.0
collected 19 items
...
----------- coverage: platform linux, python 3.9.4-final-0 -----------
Name Stmts Miss Branch BrPart Cover
-----------------------------------------------------------------------
src/__init__.py 0 0 0 0 100%
src/app.py 25 0 2 1 96%
src/blueprints/__init__.py 0 0 0 0 100%
src/blueprints/email/__init__.py 1 0 0 0 100%
src/blueprints/email/models.py 34 13 6 0 52%
src/blueprints/email/serializers.py 6 0 0 0 100%
src/blueprints/email/utils.py 20 0 2 0 100%
src/blueprints/email/views.py 54 0 14 0 100%
src/blueprints/health/__init__.py 1 0 0 0 100%
src/blueprints/health/views.py 7 0 0 0 100%
src/extensions.py 8 0 0 0 100%
-----------------------------------------------------------------------
TOTAL 156 13 24 1 89%
============================================================================================ 19 passed in 0.35s ============================================================================================
Reproducer
Versions
Version of dependencies is listed in the following files
Config
Here is the pytest relevant section from my config
[tool.pytest.ini_options]
minversion = "6.0"
testpaths = "tests"
addopts = "--cov-append --cov-branch --strict-config --verbose --code-highlight yes --color yes --cov src --cov-report term"
Code
The code in question belongs to unofficialopensource-knit/email_service
I am getting the same response if I change the --cov flag in my config file and don't pass the flag explicitly on the command line