question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--cov don't include recursively folders and files

See original GitHub issue

Summary

Expected vs actual result

I want to integrate all the python files in from my src folder only, even the untested ones.

I managed to get the expected result by indicating all the folders of my project (see Config), but it is not very practical …

I also tried with --cov or --cov . but I get the same result.

Actual

Name                              Stmts   Miss  Cover
-----------------------------------------------------
src\app.py                           10     10     0%
src\core\settings.py                 27      1    96%
src\core\sheets_utils.py             67     26    61%
src\core\stackdriver_logging.py      25     13    48%
src\core\utils.py                    24      7    71%
-----------------------------------------------------
TOTAL                               153     57    63%
Coverage HTML written to dir reports/htmlcov
Coverage XML written to file reports/coverage.xml

Expected

Name                                                          Stmts   Miss  Cover
---------------------------------------------------------------------------------
... lot of files
---------------------------------------------------------------------------------
TOTAL                                                          3414   3318     3%
Coverage HTML written to dir reports/htmlcov
Coverage XML written to file reports/coverage.xml

Reproducer

Command

python -m pytest -v

Versions

Python 3.7.9 pytest 6.2.5

Config

Expected

[tool:pytest]
norecursedirs=tests/mocks
testpaths=tests/
addopts =
    --cov src
    --cov-report term
    --cov-report html:reports/htmlcov
    --cov-report xml:reports/coverage.xml
    --junit-xml=reports/junit.xml
# https://github.com/googleapis/python-api-common-protos/issues/23#issuecomment-756495529 
filterwarnings = 
    ignore:Call to deprecated create function FieldDescriptor
    ignore:Call to deprecated create function Descriptor
    ignore:Call to deprecated create function EnumDescriptor
    ignore:Call to deprecated create function EnumValueDescriptor
    ignore:Call to deprecated create function FileDescriptor
    ignore:Call to deprecated create function OneofDescriptor
    ignore:Call to deprecated create function MethodDescriptor
    ignore:Call to deprecated create function ServiceDescriptor

Actual

[tool:pytest]
norecursedirs=tests/mocks
testpaths=tests/
addopts =
    --cov src
    --cov src/api
    --cov src/api/routes
    --cov src/api/dependencies
    --cov src/core
    --cov src/enums
    --cov src/schemas
    --cov src/schemas/big_query
    --cov src/schemas/datalake
    --cov src/schemas/mapping
    --cov src/schemas/object
    --cov src/schemas/referential
    --cov src/schemas/source
    --cov src/services
    --cov src/services/mapping
    --cov src/services/object
    --cov src/services/referential
    --cov src/services/source
    --cov-report term
    --cov-report html:reports/htmlcov
    --cov-report xml:reports/coverage.xml
    --junit-xml=reports/junit.xml
# https://github.com/googleapis/python-api-common-protos/issues/23#issuecomment-756495529 
filterwarnings = 
    ignore:Call to deprecated create function FieldDescriptor
    ignore:Call to deprecated create function Descriptor
    ignore:Call to deprecated create function EnumDescriptor
    ignore:Call to deprecated create function EnumValueDescriptor
    ignore:Call to deprecated create function FileDescriptor
    ignore:Call to deprecated create function OneofDescriptor
    ignore:Call to deprecated create function MethodDescriptor
    ignore:Call to deprecated create function ServiceDescriptor

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
FriedrichFroebelcommented, Mar 16, 2022

This is a limitation of coverage.py - as soon as it discovers a directory without an __init__.py file, it stops recursing (from your example, you do not seem to have any __init__.py files). See coverage.files.find_python_files (https://github.com/nedbat/coveragepy/blob/e1f720afb9ad31c6366f26b6fa71a5943ffa97c1/coverage/files.py#L398) for the implementation. Running this method with your directory will give you the files the collection of uncovered files will consider.

The module structure is still valid, as recent Python versions do not require you to provide (empty) __init__.py files any more for directories to be importable (implicit namespace packages/PEP 420, introduced in Python 3.3).

0reactions
beliaev-maksimcommented, Jul 4, 2022

@ionelmc I think this could be closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytest coverage: run cov over multiple folders - Stack Overflow
It was able to find the folder called tests, and run all the tests (which was split into multiple python files) within them....
Read more >
Ignoring Paths - Codecov
Add a list of paths (folders or file names) to your codecov.yml file under the ignore key to exclude ... folder/* will not...
Read more >
Unix File Permissions - NERSC Documentation
Every file (and directory) has an owner, an associated Unix group, and a set of ... Subdirectories created therein will not only have...
Read more >
Command Line Reference — gcovr 5.1 documentation
The gcovr command recursively searches a directory tree to find gcov coverage files, and generates a text summary of the code coverage.
Read more >
dotnet-coverage code coverage tool - .NET CLI - Microsoft Learn
--remove-input-files. Removes all input coverage reports that were merged. -r, --recursive. Search for coverage reports in subdirectories.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found