How to use the coverage.stop function in coverage

To help you get started, we’ve selected a few coverage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terencehonles / mailman / mailman / bin / testall.py View on Github external
initialize_3()

        # Run the tests.  XXX I'm not sure if basedir can be converted to
        # pkg_resources.
        import mailman
        basedir = os.path.dirname(mailman.__file__)
        runner = unittest.TextTestRunner(verbosity=parser.options.verbosity)
        results = runner.run(suite(parser.arguments, parser.options.randomize))
    finally:
        os.remove(cfg_out)
        os.remove(logging_cfg)
        shutil.rmtree(var_dir)

    # Turn off coverage and print a report
    if parser.options.coverage:
        coverage.stop()
        modules = [module for name, module in sys.modules.items()
                   if module
                   and name is not None
                   and name.split('.')[0] == 'mailman']
        coverage.report(modules)
    sys.exit(bool(results.failures or results.errors))
github garethr / django-clue / src / clue / testrunners / codecoverage.py View on Github external
def run_tests(test_labels, verbosity=1, interactive=True,
        extra_tests=[]):
    """
    Test runner which displays a code coverage report at the end of the
    run.
    """
    coverage.use_cache(0)
    coverage.start()
    results = django_test_runner(test_labels, verbosity, interactive, 
        extra_tests)
    coverage.stop()

    coverage_modules = []
    if test_labels:
        for label in test_labels:
            # Don't report coverage if you're only running a single
            # test case.
            if '.' not in label:
                app = get_app(label)
                coverage_modules.extend(get_all_coverage_modules(app))
    else:
        for app in get_apps():
            coverage_modules.extend(get_all_coverage_modules(app))

    if coverage_modules:
        coverage.report(coverage_modules, show_missing=1)
github galotecnia / SingularMS / singularms / daemon / tools / smstool_event_handler_tests.py View on Github external
argv = ['smstool_event_handler', 'REPORT', './sms_test_files/GSM1.M1h8yB', '1JyoAT']
        event_handler = smstool_event_handler.SmsToolEventHandler (argv, './smstool_event_handler.conf')
        event_handler.dispatch ()
        self.mocker.verify()

if __name__ == '__main__':
    try:
        coverage.use_cache(False)
        coverage.erase()
        coverage.start()
        reload(smstool_event_handler)
        try:
            unittest.main()
        finally:
            coverage.stop()
            coverage.report(smstool_event_handler)
    except ImportError:
        unittest.main()
github obeattie / sqlalchemy / test / testlib / config.py View on Github external
def _stop():
        coverage.stop()
        true_out.write("\nPreparing coverage report...\n")
        coverage.report(list(_iter_covered_files()),
                        show_missing=False, ignore_errors=False,
                        file=true_out)
    atexit.register(_stop)
github cython / cython / Tools / fwrap / runtests.py View on Github external
if options.system_pyregr and languages:
            filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, exclude_selectors,
                                    options.annotate_source, options.cleanup_workdir,
                                    options.cleanup_sharedlibs, True,
                                    options.cython_only, languages, test_bugs)
            test_suite.addTest(
                filetests.handle_directory(
                    os.path.join(sys.prefix, 'lib', 'python'+sys.version[:3], 'test'),
                    'pyregr'))

    unittest.TextTestRunner(verbosity=options.verbosity).run(test_suite)

    if 0:
        if options.coverage:
            coverage.stop()
            ignored_modules = ('Options', 'Version', 'DebugFlags', 'CmdLine')
            modules = [ module for name, module in sys.modules.items()
                        if module is not None and
                        name.startswith('Cython.Compiler.') and 
                        name[len('Cython.Compiler.'):] not in ignored_modules ]
            coverage.report(modules, show_missing=0)

        if missing_dep_excluder.tests_missing_deps:
            sys.stderr.write("Following tests excluded because of missing dependencies on your system:\n")
            for test in missing_dep_excluder.tests_missing_deps:
                sys.stderr.write("   %s\n" % test)

        if options.with_refnanny:
            import refnanny
            sys.stderr.write("\n".join([repr(x) for x in refnanny.reflog]))
github nedbat / cog / scripts / test_cog.py View on Github external
unittest.TextTestRunner().run(suite)


modnames = [
    "cogapp.cogapp",
    "cogapp.makefiles",
    "cogapp.whiteutils",
    "cogapp.test_cogapp",
    "cogapp.test_makefiles",
    "cogapp.test_whiteutils",
]

if bCoverage:
    coverage.stop()
    mods = [ sys.modules[n] for n in modnames ]
    coverage.report(mods)
github kmike / django-coverage / django_coverage / coverage_runner.py View on Github external
def run_tests(self, test_labels, extra_tests=None, **kwargs):
        coverage.use_cache(settings.COVERAGE_USE_CACHE)
        for e in settings.COVERAGE_CODE_EXCLUDES:
            coverage.exclude(e)
        coverage.start()
        results = super(CoverageRunner, self).run_tests(test_labels,
                                                        extra_tests, **kwargs)
        coverage.stop()

        coverage_modules = []
        if test_labels:
            for label in test_labels:
                label = label.split('.')[0]
                app = get_app(label)
                coverage_modules.append(self._get_app_package(app))
        else:
            for app in get_apps():
                coverage_modules.append(self._get_app_package(app))

        coverage_modules.extend(settings.COVERAGE_ADDITIONAL_MODULES)

        packages, modules, excludes, errors = get_all_modules(
            coverage_modules, settings.COVERAGE_MODULE_EXCLUDES,
            settings.COVERAGE_PATH_EXCLUDES)
github mozilla / amo-validator / validator / extras / cover.py View on Github external
def report(self, stream):
        """
        Output code coverage report.
        """
        log.debug("Coverage report")
        import coverage
        coverage.stop()
        modules = [ module
                    for name, module in sys.modules.items()
                    if self.wantModuleCoverage(name, module, stream) ]
        log.debug("Coverage report will cover modules: %s", modules)
        coverage.report(modules, file=stream)
        if self.coverHtmlDir:
            if not os.path.exists(self.coverHtmlDir):
                os.makedirs(self.coverHtmlDir)
            log.debug("Generating HTML coverage report")
            files = {}
            for m in modules:
                if hasattr(m, '__name__') and hasattr(m, '__file__'):
                    files[m.__name__] = m.__file__
            coverage.annotate(files.values())
            global_stats =  {'covered': 0, 'missed': 0, 'skipped': 0}
            file_list = []
github adamv / c64-utils / lib / cover.py View on Github external
import c64.bytestream
import c64.formats
import c64.formats.basic
import c64.formats.bootsector
import c64.formats.d64
import c64.formats.petscii
import c64.formats.prg
import c64.formats.t64

suite = unittest.TestSuite()
suite.addTest(unittest.defaultTestLoader.loadTestsFromNames(["tests"]))

testrunner = unittest.TextTestRunner()
testrunner.run(suite)

coverage.stop()
coverage.report([
    c64,
    c64.bytestream,
    c64.formats,
    c64.formats.basic,
    c64.formats.bootsector,
    c64.formats.d64,
    c64.formats.petscii,
    c64.formats.prg,
    c64.formats.t64,
    ])