[TIP] Conditional code coverage

André Caron andre.l.caron at gmail.com
Tue Jul 26 15:33:03 PDT 2016

Hi all,

I have some code base that has platform-specific code, mostly related to
how to handle SIGINT and CTRL-C for which I like to use `coverage report
--fail-under=100`.  Problem is that some code only runs on one OS, so
coverage is always partial in those cases and it's not so straightforward.

I've used Coveralls for some open source projects and their solution AFAICT
seems to be to collect the `.coverage` files in a central location and then
combine the coverage files, after which you can run the actual reporting.

However, I'm not in a position to use Coveralls for this project and
integrating a distributed coverage combine is not viable in the
short/medium term.

I'm looking for suggestions on a quick and dirty way to solve this.

One thing I thought of was using coverage's `exclude_lines` option [1] with
a platform specific token to get this:

if sys.platform == 'win32':  # pragma: cover win32

I guess this works, but it requires that I have a platform-specific
configuration file (e.g. via duplicatation or generation from a template).

Anybody have any better ideas?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160726/9c1b61b3/attachment.htm>

More information about the testing-in-python mailing list