Line coverage metrics do not add up for executed_lines and summary.covered_lines in generated coverage.json
Describe the bug Here below is an item in "files" generated from coverage.py:
"src\textual\widgets\_list_item.py": { "executed_lines": [ 1, 3, 5, 6, 7, 8, 11, 12, 19, 20, 22, 23, 25, 29, 32, 35, 36, 37 ], "summary": { "covered_lines": 15, "num_statements": 21, "percent_covered": 71.42857142857143, "percent_covered_display": "71", "missing_lines": 6, "excluded_lines": 0 }, "missing_lines": [ 26, 27, 30, 33, 38, 39 ], "excluded_lines": [],
I would expect len(executed_lines) == summary.covered_lines but the first is 18 and the later is 15. Where does the extra 3 come from?
To Reproduce
I tried this with the following:
pytest . --tb short --color no --cov=src\textual --cov-report json --continue-on-collection-errors --disable-warnings
On the https://github.com/Textualize/textual repo.
Expected behavior My expectation is: covered_lines + executed_lines + excluded_lines == summary.num_statements, but this seems to not be the case?
I'd like to reproduce this, but I don't use poetry so I'm not sure how to get everything in order. Can you give the exact commands you used, starting with git clone?
I think the three lines are the docstrings, but I'm not sure why they are treated differently.
Yeah so here's the repo: https://github.com/JohnPeng47/textual-neutered
- Clone
- Install poetry in your current python env
- cd into repo and run
poetry installto get deps - run
poetry shellto activate project venv with deps installed from 3 - run
pytest . --tb short --color no --cov=src/textual --cov-report json --continue-on-collection-errors --disable-warnings - [OPTIONAL] I have a script test_coverage.py that basically checks that this conditions is true for all coverage files:
missing_check = len(missing_lines) + len(executed_lines) + len(excluded_lines) == total_stmts
Also a shorter example here:
"__init__.py": { "executed_lines": [ 0 ], "summary": { "covered_lines": 0, "num_statements": 0, "percent_covered": 100, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0 }, "missing_lines": [], "excluded_lines": [],
In this example, both covered_lines and num_statements should be 1 right, not 0?
Also another thing that I just noticed now, is that the coverage collected on the same repo is different on Windows vs. Linux. Is this just inherent to the OS differences in settrace impl?
There is no OS difference in the settrace implementation. Likely the difference is do to OS differences in textual repo. If you don't think that's the case, let's look at some more specific details.
Ahh no I think that makes sense. But could you confirm: len(missing_lines) + len(executed_lines) + len(excluded_lines) == total_stmts
Is invariant for every file under coverage?
Hey sorry to keep pestering, but do you think you can just answer that one question above? My coverage diffing code is broken for some reason, and I just want to be sure that the above condition should hold
But could you confirm: len(missing_lines) + len(executed_lines) + len(excluded_lines) == total_stmts
Is invariant for every file under coverage?
As I mentioned, docstrings complicate matters. I'm also not sure what number you mean by total_stmts. That's not a number in the JSON report.