~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/testing/layers.py

  • Committer: Barry Warsaw
  • Date: 2013-10-18 21:44:31 UTC
  • Revision ID: barry@list.org-20131018214431-f9t3287twcvdckmq
 * When --sort is used, watch out for continuation lines, which shouldn't get
   sorted.

 * Fix stderr output in sub-runners, and move the -e test option to -E.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
        if cls.stderr:
144
144
            test_config += dedent("""
145
145
            [logging.root]
146
 
            propagate: yes
147
146
            level: debug
148
147
            """)
149
148
        # Enable log message propagation and reset the log paths so that the
154
153
                continue
155
154
            logger_name = 'mailman.' + sub_name
156
155
            log = logging.getLogger(logger_name)
157
 
            #log.propagate = True
 
156
            log.propagate = cls.stderr
158
157
            # Reopen the file to a new path that tests can get at.  Instead of
159
158
            # using the configuration file path though, use a path that's
160
159
            # specific to the logger so that tests can find expected output
170
169
                propagate: yes
171
170
                level: debug
172
171
                """), dict(name=sub_name, path=path))
173
 
        # zope.testing sets up logging before we get to our own initialization
174
 
        # function.  This messes with the root logger, so explicitly set it to
175
 
        # go to stderr.
 
172
        # The root logger will already have a handler, but it's not the right
 
173
        # handler.  Remove that and set our own.
176
174
        if cls.stderr:
177
175
            console = logging.StreamHandler(sys.stderr)
178
176
            formatter = logging.Formatter(config.logging.root.format,
179
177
                                          config.logging.root.datefmt)
180
178
            console.setFormatter(formatter)
181
 
            logging.getLogger().addHandler(console)
 
179
            root = logging.getLogger()
 
180
            del root.handlers[:]
 
181
            root.addHandler(console)
182
182
        # Write the configuration file for subprocesses and set up the config
183
183
        # object to pass that properly on the -C option.
184
184
        config_file = os.path.join(cls.var_dir, 'test.cfg')
209
209
    # Flag to indicate that loggers should propagate to the console.
210
210
    stderr = False
211
211
 
212
 
    @classmethod
213
 
    def enable_stderr(cls):
214
 
        """Enable stderr logging if -e/--stderr is given.
215
 
 
216
 
        We used to hack our way into the zc.testing framework, but that was
217
 
        undocumented and way too fragile.  Well, this probably is too, but now
218
 
        we just scan sys.argv for -e/--stderr and enable logging if found.
219
 
        Then we remove the option from sys.argv.  This works because this
220
 
        method is called before zope.testrunner sees the options.
221
 
 
222
 
        As a bonus, we'll check an environment variable too.
223
 
        """
224
 
        if '-e' in sys.argv:
225
 
            cls.stderr = True
226
 
            sys.argv.remove('-e')
227
 
        if '--stderr' in sys.argv:
228
 
            cls.stderr = True
229
 
            sys.argv.remove('--stderr')
230
 
        if len(os.environ.get('MM_VERBOSE_TESTLOG', '').strip()) > 0:
231
 
            cls.stderr = True
232
 
 
233
212
    # The top of our source tree, for tests that care (e.g. hooks.txt).
234
213
    root_directory = None
235
214