Generating coverage reports when tests use Dask distributed

I have a Python package built around Dask distributed. I would like to run tests via pytest and have the coverage from these tests used for generating a report of the covered lines (e.g. via --cov and --cov-report). However, when using Dask distributed it seems that the code coverage of the run is not fully reflected, likely due to the distributed nature of the workers.

Are there any suggestions for how to deal with such testing? I tried using the distributed.utils_test.client pytest fixture when running my tests, but the client is orders of magnitude slower than just using from dask.distributed.default_client as my client, which is what I have been using. The distributed.utils_test.gen_cluster also doesn’t seem ideal because I want to run the tests across multiple cores, both to reflect their actual use and because the test suite takes too long otherwise.

Actually, this was pretty easy!

All you have to do is coverage combine -a and then coverage xml.

1 Like