コード例 #1
0
ファイル: coverage_plugin.py プロジェクト: timeyyy/pybuilder
def do_coverage(project, logger, reactor, execution_prefix, execution_name,
                target_task, shortest_plan):
    """
    This function MUST ALWAYS execute in a fork.
    The sys.modules will be manipulated extensively to stage the tests properly, which may affect execute down the line.
    It's best to simple let this method exit and the fork die rather than to try to recover.
    """
    source_tree_path = project.get_property("dir_source_main_python")
    reset_modules = project.get_property("%s_reset_modules" % execution_prefix)
    allow_non_imported_modules = project.get_property(
        "%s_allow_non_imported_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])

    patch_multiprocessing(coverage.config)
    try:
        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)
    finally:
        reverse_patch_multiprocessing()

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

    failure = _build_coverage_report(project, logger, execution_name,
                                     execution_prefix, coverage, modules)

    if non_imported_modules and not allow_non_imported_modules:
        raise BuildFailedException(
            "Some modules have not been imported and have no coverage")

    if failure:
        raise failure
コード例 #2
0
def do_coverage(project, logger, reactor, execution_prefix, execution_name, target_task, shortest_plan):
    """
    This function MUST ALWAYS execute in a fork.
    The sys.modules will be manipulated extensively to stage the tests properly, which may affect execute down the line.
    It's best to simple let this method exit and the fork die rather than to try to recover.
    """
    source_tree_path = project.get_property("dir_source_main_python")
    reset_modules = project.get_property("%s_reset_modules" % execution_prefix)
    allow_non_imported_modules = project.get_property("%s_allow_non_imported_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])

    patch_multiprocessing(coverage.config)
    try:
        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)
    finally:
        reverse_patch_multiprocessing()

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

    failure = _build_coverage_report(project, logger, execution_name, execution_prefix, coverage, modules)

    if non_imported_modules and not allow_non_imported_modules:
        raise BuildFailedException("Some modules have not been imported and have no coverage")

    if failure:
        raise failure