[TIP] Conditional code coverage
andre.l.caron at gmail.com
Tue Jul 26 15:33:03 PDT 2016
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
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  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...
More information about the testing-in-python