From 6e9025cbea1040ac67058f4b5cfd51d2e20832fd Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Wed, 23 Jan 2013 17:36:41 +0100 Subject: [PATCH] [IMP] oe initialize: added --coverage flag. bzr revid: vmt@openerp.com-20130123163641-uumkklqpaxkyvsr8 --- openerpcommand/initialize.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/openerpcommand/initialize.py b/openerpcommand/initialize.py index 3393c9a02d4..34c188bd583 100644 --- a/openerpcommand/initialize.py +++ b/openerpcommand/initialize.py @@ -70,8 +70,19 @@ def run(args): else: module_names = ['base'] + if args.coverage: + import coverage + # Without the `include` kwarg, coverage generates 'memory:0xXXXXX' + # filenames (which do not exist) and cause it to crash. No idea why. + cov = coverage.coverage(branch=True, include='*.py') + cov.start() openerp.netsvc.init_logger() registry = install_openerp(args.database, not args.no_create, module_names, not config['without_demo']) + if args.coverage: + cov.stop() + cov.html_report(directory='coverage') + # If we wanted the report on stdout: + # cov.report() # The `_assertion_report` attribute was added on the registry during the # OpenERP 7.0 development. @@ -99,5 +110,9 @@ def add_parser(subparsers): ' (use the `run-tests` command to choose specific' ' tests to run against an existing database).' ' Demo data are installed.') + parser.add_argument('--coverage', action='store_true', + help='report code coverage (particularly useful with --tests).' + ' The report is generated in a coverage directory and you can' + ' then point your browser to coverage/index.html.') parser.set_defaults(run=run)