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

Take advantage of .coverage being a SQLite database #847

Closed
simonw opened this issue Jun 14, 2020 · 4 comments
Closed

Take advantage of .coverage being a SQLite database #847

simonw opened this issue Jun 14, 2020 · 4 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 14, 2020

The .coverage file generated by running pytest-cov is now a SQLite database!

I could do something interesting with this. Maybe after each test run for a new commit I could store that database file somewhere?

Lots of interesting challenges here.

I got a change into coveragepy last year which helps make the custom SQL functions available for doing fun things in Datasette: nedbat/coveragepy#868

Bigger challenge: if I have a DB file for every commit, that's hundreds (potentially thousands) of DB files. Datasette isn't designed to handle thousands of files like that.

So, do I figure out how to have Datasette open a file on-command for just a single request? Or, an easier option, do I copy data from those files into a single database with a modified schema to include the commit hash in each table row?

(Following on from #841 and #844)

@simonw
Copy link
Owner Author

simonw commented Jun 14, 2020

Filed a related issue with some ideas against coveragepy here: nedbat/coveragepy#999

@simonw
Copy link
Owner Author

simonw commented Jun 14, 2020

On closer inspection, I don't know if there's that much useful stuff you can do with the data from .coverage on its own.

Consider the following query against a .coverage run against Datasette itself:

select file_id, context_id, numbits_to_nums(numbits) from line_bits

_coverage__select_file_id__context_id__numbits_to_nums_numbits__from_line_bits

It looks like this tells me which lines of which files were executed during the test run. But... without the actual source code, I don't think I can calculate the coverage percentage for each file. I don't want to count comment lines or whitespace as untested for example, and I don't know how many lines were in the file.

If I'm right that it's not possible to calculate percentage coverage from just the .coverage data then I'll need to do something a bit more involved - maybe parsing the coverage.xml report and loading that into my own schema?

@simonw
Copy link
Owner Author

simonw commented Jun 14, 2020

Here's the plugin that adds those custom SQLite functions:

from datasette import hookimpl
from coverage.numbits import register_sqlite_functions


@hookimpl
def prepare_connection(conn):
    register_sqlite_functions(conn)

@simonw
Copy link
Owner Author

simonw commented Jun 28, 2020

I'm happy enough with https://codecov.io/gh/simonw/datasette that I'm not going to spend any more time on this.

@simonw simonw closed this as completed Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant