~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to Mailman/bin/testall.py

  • Committer: Barry Warsaw
  • Date: 2007-07-02 01:49:34 UTC
  • Revision ID: barry@python.org-20070702014934-4dej6tvbh64ypxo7
Add support for code coverage with 'testall --coverage'.  However, I'm not
convinced this is totally accurate as a full test run shows almost no coverage
in the Mailman.database.model modules even though I /know/ they're getting
executed.

I'll need to figure this out, but eventually we'll convert fully to setuptools
and then we'll use the nosetests to do testing and coverage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    parser.add_option('-e', '--stderr',
75
75
                      default=False, action='store_true',
76
76
                      help=_('Propagate log errors to stderr.'))
 
77
    parser.add_option('-c', '--coverage',
 
78
                      default=False, action='store_true',
 
79
                      help=_('Enable code coverage.'))
77
80
    opts, args = parser.parse_args()
78
81
    return parser, opts, args
79
82
 
149
152
    if not args:
150
153
        args = ['.']
151
154
 
 
155
    # Turn on code coverage if selected.
 
156
    if opts.coverage:
 
157
        try:
 
158
            import coverage
 
159
        except ImportError:
 
160
            opts.coverage = False
 
161
        else:
 
162
            coverage.start()
 
163
 
152
164
    # Set up the testing configuration file both for this process, and for all
153
165
    # sub-processes testing will spawn (e.g. the qrunners).
154
166
    #
199
211
        basedir = os.path.dirname(Mailman.__file__)
200
212
        runner = unittest.TextTestRunner(verbosity=opts.verbosity)
201
213
        results = runner.run(suite(args))
202
 
 
203
214
    finally:
204
215
        os.remove(cfg_out)
205
216
        shutil.rmtree(var_prefix)
206
217
 
 
218
    # Turn off coverage and print a report
 
219
    if opts.coverage:
 
220
        coverage.stop()
 
221
        modules = [module for name, module in sys.modules.items()
 
222
                   if module
 
223
                   and name is not None
 
224
                   and name.split('.')[0] == 'Mailman']
 
225
        coverage.report(modules)
207
226
    sys.exit(bool(results.failures or results.errors))
208
227
 
209
228