[TIP] Conditional code coverage

Ned Batchelder ned at nedbatchelder.com
Wed Jul 27 06:54:01 PDT 2016


You can use environment variables in the .coveragerc file, so you can 
create a pattern for pragmas that uses environmental data. For example: 
https://github.com/habnabit/ebb-lint/blob/master/.coveragerc :

    [report]
    exclude_lines =
         pragma: no ${TOX_ENVNAME}
         pragma: no ?cover

--Ned.


On 7/26/16 6:33 PM, André Caron wrote:
> 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?
>
> Thanks,
>
> André
>
> [1]: 
> https://coverage.readthedocs.io/en/coverage-4.1/excluding.html#advanced-exclusion
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

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


More information about the testing-in-python mailing list