def do_coverage(project, logger, reactor, execution_prefix, execution_name, target_task, shortest_plan):
    source_tree_path = project.get_property("dir_source_main_python")
    reset_modules = project.get_property("%s_reset_modules" % execution_prefix)
    module_names = _discover_modules_to_cover(project)

    for module_name in module_names:
        logger.debug("Module '%s' coverage to be verified", module_name)

    if reset_modules and not is_windows():
        _delete_non_essential_modules()
        __import__("pybuilder.plugins.python")  # Reimport self

    # Starting fresh
    from coverage import coverage as coverage_factory

    coverage = coverage_factory(cover_pylib=False, branch=True, source=[source_tree_path])

    try:
        _start_coverage(project, coverage)

        if shortest_plan:
            reactor.execute_task_shortest_plan(target_task)
        else:
            reactor.execute_task(target_task)
    finally:
        _stop_coverage(project, coverage)

    module_exceptions = project.get_property("%s_exceptions" % execution_prefix)
    modules = _list_all_covered_modules(logger, module_names, module_exceptions)

    failure = _build_coverage_report(project, logger, execution_name, execution_prefix, coverage, modules)
    if failure:
        raise failure
This function MUST ALWAYS execute in a fork.
dataset/ETHPy150Open pybuilder/pybuilder/src/main/python/pybuilder/plugins/python/coverage_plugin.py/do_coverage