Use sqlite .coverage file to do cool stuff #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a PR that combines a lot of stuff (mentioned in #6), so I'm not expecting it to be merged as is, but I thought I'd share at this point even if it's not quite ready. I have been using this for several months now and found it useful.
Also my elisp is probably pretty bad!
Basically 2 main features:
The ability to use the
.coverage
SQLite file directly, without needing thecoverage.xml
report to be generated, for normal overlay analysis. The SQLite file is less preferred, because the XML file contains processing done to handling empty lines and docstrings etc,. - analysis that could not easily be reproduced in elisp, it requires a Python parser.This requires using some internals of the coverage SQLite schema, and reproducing some of the "packing" logic for line numbers (see https://github.com/nedbat/coveragepy/blob/master/coverage/numbits.py ). However, we include version checking of the file, and if the schema changes in the future, we can add support for multiple schemas easily.
If
--cov-context=test
has been used, it adds the ability to find which tests executed which lines of code. This can only be implemented using the SQLite file, as the XML doesn't contain this info. The only user interface on this at the moment is the commandpython-coverage-rerun-pytest-current-region
command, which is the only interface I needed. It basically allows you to put your cursor somewhere in the code, doM-x python-coverage-rerun-pytest-current-region
and get a pytest command line for rerunning the tests that executed that code, like this:This is super useful on some occasions!