capturemock scans sys.modules, which can interact badly with six module
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CaptureMock |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
The six module has something called six.moves which creates fake module objects in sys.modules that are proxies that lazy load the real modules.
When I use six and capturemock together, I get errors because capturemock scans through all the modules in sys.modules and sometimes chokes on one of them:
```
❯ py.test -k test_get_
Test session starts (darwin, 2.6.7)
plugins: capturelog, cov, sugar
―――――――
../../lib/
> interceptor = interceptPython
../../lib/
> handler.
../../lib/
> import_handler = ImportHandler(
../../lib/
> self.handleImpo
../../lib/
> loadingMods = self.modulesLoa
../../lib/
> modAttrName = self.findAttrib
../../lib/
> if getattr(module, currAttrName) is attr:
../../lib/
> raise AttributeError("%s could not be imported " % self.name)
E AttributeError: dbm_gnu could not be imported
```
Here's a patch that makes CaptureMock not error out if it can find an attribute it was expecting to find:
```
diff --git a/capturepython
index 0483931..3ac8060 100644
--- a/capturepython
+++ b/capturepython.py
@@ -137,7 +137,7 @@ class ImportHandler:
# Can't assume the attribute will have the same name of the module,
# because of "import x as y" construct
for currAttrName in dir(module):
- if getattr(module, currAttrName) is attr:
+ if getattr(module, currAttrName, None) is attr:
def shouldIntercept
```
Changed in capturemock: | |
status: | Fix Committed → Fix Released |
Integrated the suggested patch. Let me know if it's OK and I'll release 1.0.2. (I fixed a few other things last week)