Half-baked ideas

Generic Python reverse test coverage tool

9 thoughts
last posted Jan. 30, 2019, 10:55 a.m.
0
get stream as: markdown or atom
0

In an IRC discussion, the topic of collecting and using reverse test coverage information came up.

0

First some definitions:

Forward test coverage answers the question:
Given these tests, what part of the codebase gets executed?

Reverse test coverage answers the question:
Given this part of the codebase, which tests execute it?

0

Most conventional test coverage tools answer the "forward" coverage question: developers want to know what code the tests exercise or miss.

Reverse coverage, by contrast, is relatively specialised. One main application of it is in the context of big, complex, automated integration builds, where you only want to re-run the subset of tests that depend on the code that changed with each commit, rather than the full test suite.

As a result, reverse coverage support tends to be obscure, or locked away inside heavy-weight distributed build systems (such as Google's formerly in-house Bazel).

0

However, reverse coverage is far from being useful only at that big scale. Imagine being able to:

  • Intelligently rerun only the changed code's tests coverage, while doing interactive test-driven development
  • Query for a list of tests that execute some bit code, while learning a new codebase
0

Those features could be baked into existing tools and test runners (unittest, py.test, trial, …), but that might involve a lot of redundant work.

Python already has a de facto standard generic code coverage tool, coverage.py. One of the great things about it that it can invoke any Python tool or script and collect configurable coverage information about its execution, without any special support from the tool being invoked.

Could this same generic approach work for reverse coverage?

0

Update: coverage.py now has support for capturing this!

0

https://python-tia.readthedocs.io/The generic Test Impact Analysis (TIA) preprocessor for test tools.

This project provides this useful overview of related tools:

0

https://github.com/tarpas/pytest-testmon

This pytest plugin looks like a solid and user-friendly implementation of the idea for faster TDD and CI.