Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sqlite .coverage file to do cool stuff #7

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

spookylukey
Copy link

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:

  1. The ability to use the .coverage SQLite file directly, without needing the coverage.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.

  2. 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 command python-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, do M-x python-coverage-rerun-pytest-current-region and get a pytest command line for rerunning the tests that executed that code, like this:

pytest path/to/tests.py::test_1 path/to/tests.py::test_2 

This is super useful on some occasions!

Status:

This kind of works:

- find .coverage if coverage.xml is not available
- read nubmits from SQLite file
- ignore blank lines

Not done:

- it marks some lines as missing that coverage.xml does not, due
  to the analysis that coveragepy does. In particular:
  - docstrings
  - comments

- doesn't handle partial coverage at all yet.
@wbolster wbolster added the enhancement New feature or request label Sep 19, 2022
@wbolster wbolster linked an issue Sep 19, 2022 that may be closed by this pull request
@wbolster wbolster marked this pull request as draft September 19, 2022 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for showing contexts
2 participants