Code coverage through unit tests running in sub-processes/threads: Locally and automated on GitHub

Saransh Chopra

Saransh Chopra

Saransh is an engineering junior at the University of Delhi, pursuing a major in Information Technology and Mathematics. In daylight, he work towards his academic skills and professional commitments, and by night, he develops and maintains open-source research software, which he believes are the key to collaborative and reproducible research. He is currently a fellow at the Institute for Research and Innovation in Software for High Energy Physics (IRIS-HEP), working on the first major release of Vector. He is also working as a technical writer for FluxML, which is being funded by the Julia Programming Language. He is interested in everything a Research Software Engineer and a Machine Learning Engineer do, including Scientific Machine Learning, code optimization, developing packages, technical writing, building infrastructures, developing open-source research software, JuliaLang, and Python.

    Abstract

    Unit testing and code coverage are two essential aspects of an open-source codebase. These unit tests often run in spawned sub-processes or threads as sub-processes or multi-threading allow them to run parallelly. However, running unit tests in a sub-process creates a problem; as the documentation of `coverage.py` says — *“Measuring coverage in those sub-processes can be tricky because you have to modify the code spawning the process to invoke coverage.py.”*. As we will see in this tutorial, as soon as we run unit tests inside a sub-process, the coverage module ignores them completely, and the coverage value goes down. Through this talk, we will build up a solution (using `coverage.py` itself) to tackle this problem! Prerequisites - - familiarity with unit testing and code coverage in Python - familiarity with CI/CD using GitHub Actions - knowledge of multi-threading, multi-processing, CodeCov, and basic data structures like queue would be helpful but is not mandatory

    Description

    Video

    Location

    R2

    Date

    Day 1 • 10:45-11:15 (GMT+8)

    Language

    English talk

    Level

    Intermediate

    Category

    Testing