100% but unused python files not detected

We’ve been using, and getting 100% coverage, but just realised that some .py files were not being imported anywhere and so were effectively dead files. We’ve just fixed the issue by making sure those files are imported and used, but is there any way that could automatically detect this?

Does this make sense @nedbat ?

Many thanks in advance has a --source=somewhere option. It will then explore the tree at somewhere looking for files that weren’t imported. The usual value for somewhere is “.”: --source=.


Adding to Ned’s comments, here’s a snippet from our .coveragerc, which also includes omit to suppress those files intentionally ignored/unused.

branch        = True
cover_pylib   = False
concurrency   = thread
data_file     = $PROJECT_COVERDIR/.coverage
debug         =
source        =
timid         = False
omit          =
1 Like

excellent thanks! Just what we were looking for :slight_smile:

Mhm… I do have similar problems. I try to setup a demo project to illustrate the use of coverage. I have an untested file in there and it is not discovered when using “source=”.

There is also an Issue about that.

The setup in my pyproject.toml

command_line = "--module pytest"
source = ["."]
omit = ["*/tests/*"]

This is the project tree where is ignored by coverage.

├── pyproject.toml
├── src
│   └── fruits
│       ├──
│       ├──
│       └──
└── tests

That is the report output

Name                     Stmts   Miss  Cover
src/fruits/       8      0   100%
TOTAL                        8      0   100%