show python coverage information directly in emacs

Overview

python-coverage.el

This is an experimental Emacs package to report code coverage output produced by Python's coverage package directly inside Emacs buffers.

Best used together with python-pytest.el.

Screenshot

mandatory screenshot

Overlays

Minor mode for automagically updated overlays:

  • python-coverage-overlay-mode

Alternatively, commands for manually updated overlays:

  • python-coverage-overlay-refresh
  • python-coverage-overlay-remove-all

Navigation commands:

  • python-coverage-overlay-jump-next
  • python-coverage-overlay-jump-previous
  • python-coverage-overlay-jump-first

Flycheck checker

Run flycheck-select-checker, pick python-coverage.

Coverage data

This package reads the XML output produced by Python's coverage package. Usually this file is named coverage.xml.

With plain coverage:

$ coverage xml

With pytest-cov, pass --cov-report=xml, e.g. via pyproject.toml:

[tool.pytest.ini_options]
addopts = [
  "--cov=your-package",
  "--cov=test",
  "--cov-report=xml",
]

Customization

Command for manual coverage file selection:

  • python-coverage-select-coverage-file

Customizable settings (see their description for details) in the python-coverage group, e.g. via M-x customize-group:

  • python-coverage-default-file-name
  • python-coverage-overlay-width

Styling via custom faces, e.g. via M-x customize-face:

  • python-coverage-overlay-missing
  • python-coverage-overlay-partial
  • python-coverage-overlay-missing-outdated
  • python-coverage-overlay-partial-outdated

Note: by default this package inherits from magit-diff-* faces, which should work in most themes. This requires magit to be installed, but it's not otherwise used.

Credits

This package was created by wouter bolsterlee (@wbolster).

License

BSD; see LICENSE.rst.

Comments
  • Upload on MELPA

    Upload on MELPA

    Hi! Just wanted to say that I'm using this package and I find it super useful - it's much better and less invasive than some of the other ones on GitHub/MELPA.

    Do you have any plans to upload it on MELPA? Anything I can do to help?

    enhancement 
    opened by AndreaOrru 2
  • Use sqlite .coverage file to do cool stuff

    Use sqlite .coverage file to do cool stuff

    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!

    enhancement 
    opened by spookylukey 0
  • Support for showing contexts

    Support for showing contexts

    A cool thing you can do with coverage and pytest-cov is dynamic contexts, which results in a neat feature in the HTML report, where you can see the tests that executed a line of code.

    Obviously it would be cool to have this directly from my editor in some way. Seeing that this package is already overlapping with this functionality, I thought this might be a good place for it. Would you be interested in having a feature like that?

    I'm aware it's a lot of work, so it's something I might tackle myself, before doing so I just wanted to know what your thoughts on that becoming part of this package. I'm not a brilliant elisp hacker but this is probably a good project for me to take on at my level, and it certainly scratches an itch for me.

    There are some significant issues. The contexts data is not exported to coverage.xml as far as I can see, so that is a bit of a blocker.

    However, another way to get the data is directly via the .coverage data file, which is an SQLite file (since version 5, 2018 - https://coverage.readthedocs.io/en/coverage-5.5/changes.html#version-5-0a2-2018-09-03). This file doesn't have a fixed schema, but it does have an easy way to check the schema version: select version from coverage_schema; So you know if it is different from what you expect and you can support multiple versions probably fairly easily for our needs.

    If you switched to using the SQLite data directly, you get an additional advantage - there is no need to run coverage xml as an extra step first. There would probably be other advantages too in terms of more powerful querying of the data. It may also have performance benefits if you have a large .coverage file - using coverage.xml requires you to parse the whole XML file every time to get just the data you are interested. Would you be open to switching from coverage.xml parsing to using the SQLite file?

    Thanks!

    opened by spookylukey 2
  • Add support for project relative files

    Add support for project relative files

    Currently this module uses absolute path to file. But this leads to missing files in case of virtualization. Basically I do have docker container that runs tests and absolute path differs from what this module tries to find.

    I see 2 possible solutions to this:

    • add alias-path or something like this variable to replace part of path so sources and system path matches
    • use relative paths: find coverage.xml consider this folder as root for project and search files based on this

    what do you think? I'm not advanced enough with elisp to do it myself :P (but I'll try it anyway, and will appreciate some hints)

    enhancement 
    opened by Randomneo 0
  • Added a minor mode

    Added a minor mode

    When enabled, it sets the checker to python-coverage, and changes the style of flycheck. When disabled, restores flycheck's previous checker and style.

    This is how it looks like: image

    enhancement 
    opened by AndreaOrru 3
Owner
wouter bolsterlee
wouter bolsterlee
Coverage plugin for pytest.

Overview docs tests package This plugin produces coverage reports. Compared to just using coverage run this plugin does some extras: Subprocess suppor

pytest-dev 1.4k Dec 29, 2022
a plugin for py.test that changes the default look and feel of py.test (e.g. progressbar, show tests that fail instantly)

pytest-sugar pytest-sugar is a plugin for pytest that shows failures and errors instantly and shows a progress bar. Requirements You will need the fol

Teemu 963 Dec 28, 2022
Show surprise when tests are passing

pytest-pikachu pytest-pikachu prints ascii art of Surprised Pikachu when all tests pass. Installation $ pip install pytest-pikachu Usage Pass the --p

Charlie Hornsby 13 Apr 15, 2022
Based on the selenium automatic test framework of python, the program crawls the score information of the educational administration system of a unive

whpu_spider 该程序基于python的selenium自动化测试框架,对某高校的教务系统的成绩信息实时爬取,在检测到成绩更新之后,会通过电子邮件的方式,将更新的成绩以文本的方式发送给用户,可以使得用户在不必手动登录教务系统网站时,实时获取成绩更新的信息。 该程序仅供学习交流,不可用于恶意攻

null 1 Dec 30, 2021
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Jan 2, 2023
Selenium-python but lighter: Helium is the best Python library for web automation.

Selenium-python but lighter: Helium Selenium-python is great for web automation. Helium makes it easier to use. For example: Under the hood, Helium fo

Michael Herrmann 3.2k Dec 31, 2022
Pynguin, The PYthoN General UnIt Test geNerator is a test-generation tool for Python

Pynguin, the PYthoN General UnIt test geNerator, is a tool that allows developers to generate unit tests automatically.

Chair of Software Engineering II, Uni Passau 997 Jan 6, 2023
Python Projects - Few Python projects with Testing using Pytest

Python_Projects Few Python projects : Fast_API_Docker_PyTest- Just a simple auto

Tal Mogendorff 1 Jan 22, 2022
Green is a clean, colorful, fast python test runner.

Green -- A clean, colorful, fast python test runner. Features Clean - Low redundancy in output. Result statistics for each test is vertically aligned.

Nathan Stocks 756 Dec 22, 2022
Scalable user load testing tool written in Python

Locust Locust is an easy to use, scriptable and scalable performance testing tool. You define the behaviour of your users in regular Python code, inst

Locust.io 20.4k Jan 4, 2023
A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.

PyAutoGUI PyAutoGUI is a cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard. pip inst

Al Sweigart 7.5k Dec 31, 2022
splinter - python test framework for web applications

splinter - python tool for testing web applications splinter is an open source tool for testing web applications using Python. It lets you automate br

Cobra Team 2.6k Dec 27, 2022
Let your Python tests travel through time

FreezeGun: Let your Python tests travel through time FreezeGun is a library that allows your Python tests to travel through time by mocking the dateti

Steve Pulec 3.5k Dec 29, 2022
HTTP client mocking tool for Python - inspired by Fakeweb for Ruby

HTTPretty 1.0.5 HTTP Client mocking tool for Python created by Gabriel Falcão . It provides a full fake TCP socket module. Inspired by FakeWeb Github

Gabriel Falcão 2k Jan 6, 2023
A utility for mocking out the Python Requests library.

Responses A utility library for mocking out the requests Python library. Note Responses requires Python 2.7 or newer, and requests >= 2.0 Installing p

Sentry 3.8k Jan 3, 2023
A test fixtures replacement for Python

factory_boy factory_boy is a fixtures replacement based on thoughtbot's factory_bot. As a fixtures replacement tool, it aims to replace static, hard t

FactoryBoy project 3k Jan 5, 2023
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-

Kirill Klenov 871 Dec 25, 2022
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 1, 2023
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.

Mimesis - Fake Data Generator Description Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes

Isaak Uchakaev 3.8k Dec 29, 2022