~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/profile/tests.py

  • Committer: Curtis Hovey
  • Date: 2011-12-25 21:05:02 UTC
  • mto: This revision was merged to the branch mainline in revision 14602.
  • Revision ID: curtis.hovey@canonical.com-20111225210502-tu8smu7ajr8pcgtm
Do not registerer an ErrorReportingUtility if one is already registered.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    BeforeTraverseEvent,
19
19
    EndRequestEvent,
20
20
    )
21
 
from zope.component import getSiteManager
 
21
from zope.component import (
 
22
    getSiteManager,
 
23
    queryUtility,
 
24
    )
 
25
from zope.error.interfaces import IErrorReportingUtility
22
26
 
23
27
import lp.services.webapp.adapter as da
24
28
from lp.services.webapp.errorlog import ErrorReportingUtility
360
364
        self.profile_dir = self.makeTemporaryDirectory()
361
365
        self.memory_profile_log = os.path.join(self.profile_dir, 'memory_log')
362
366
        self.pushConfig('profiling', profile_dir=self.profile_dir)
363
 
        self.eru = ErrorReportingUtility()
364
 
        sm = getSiteManager()
365
 
        sm.registerUtility(self.eru)
366
 
        self.addCleanup(sm.unregisterUtility, self.eru)
 
367
        eru = queryUtility(IErrorReportingUtility)
 
368
        if eru is None:
 
369
            # Register an Error reporting utility for this layer.
 
370
            # This will break tests when run with an ERU already registered.
 
371
            self.eru = ErrorReportingUtility()
 
372
            sm = getSiteManager()
 
373
            sm.registerUtility(self.eru)
 
374
            self.addCleanup(sm.unregisterUtility, self.eru)
367
375
 
368
376
    def endRequest(self, path='/', exception=None, pageid=None, work=None):
369
377
        start_event = self._get_start_event(path)