How To Determine Which Unit Test Covered a Function or Method

Coverage.py doesn't yet provide this feature, but there's an open ticket where we are kicking around ideas: https://github.com/nedbat/coveragepy/issues/170

To read the old history of this issue, check out the old ticket (in the BitBucket tracker)


Smother is a wrapper utility around coverage.py that measures code coverage separately for each test in a test suite. Its main features include:

  • Fast and reliable coverage tracking using coverage.py.
  • Ability to lookup which tests visit an arbitrary section of your application code.
  • Ability to convert version control diffs into a subset of affected tests to rerun.

It supports py.test and nose.


I don't know whether this code is still functional in the current ecosystem (in particular current coverage version and nose / nose 2 plugin APIs), but the the figleaf-sections plugin from the figleaf package provides this feature.

http://darcs.idyll.org/~t/projects/figleaf/doc/

If I recall, it was a nice proof of concept and I'm sure useful, but I think there were a few rough edges, I'd love it if somebody picked up the idea and really made it work smoothly!