~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 08:40:16 UTC
  • mfrom: (5642.4.6 712474-module-available)
  • Revision ID: pqm@pqm.ubuntu.com-20110817084016-600z65qzqmmt44w7
(vila) ModuleAvailableFeature don't try to imported already imported
 modules. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
        self.module_name = module_name
167
167
 
168
168
    def _probe(self):
169
 
        try:
170
 
            self._module = __import__(self.module_name, {}, {}, [''])
 
169
        sentinel = object()
 
170
        module = sys.modules.get(self.module_name, sentinel)
 
171
        if module is sentinel:
 
172
            try:
 
173
                self._module = __import__(self.module_name, {}, {}, [''])
 
174
                return True
 
175
            except ImportError:
 
176
                return False
 
177
        else:
 
178
            self._module = module
171
179
            return True
172
 
        except ImportError:
173
 
            return False
174
180
 
175
181
    @property
176
182
    def module(self):