[英]Imports are not properly handled while running nosetests in multi process mode
Given a test case: 给定一个测试用例:
import unittest
import mock
class TestTest(unittest.TestCase):
def test_test(self):
print dir(__import__('google'))
with mock.patch('google.appengine.api.urlfetch.fetch'):
pass
- -
$ nosetests --with-gae --processes=0
Ran 1 test in 0.187s
OK
- -
$ nosetests --with-gae --processes=1
======================================================================
ERROR: test_test (test_test.TestTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/sadovnychyi/example/test_test.py", line 8, in test_test
with mock.patch('google.appengine.api.urlfetch.fetch'):
File "/usr/local/lib/python2.7/site-packages/mock.py", line 1252, in __enter__
self.target = self.getter()
File "/usr/local/lib/python2.7/site-packages/mock.py", line 1414, in <lambda>
getter = lambda: _importer(target)
File "/usr/local/lib/python2.7/site-packages/mock.py", line 1102, in _importer
thing = _dot_lookup(thing, comp, import_path)
File "/usr/local/lib/python2.7/site-packages/mock.py", line 1092, in _dot_lookup
return getattr(thing, comp)
AttributeError: 'module' object has no attribute 'appengine'
-------------------- >> begin captured stdout << ---------------------
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'net']
Any idea why its happening and how to fix it? 知道为什么会发生以及如何解决吗?
So I missed a line in nosegae.py: 所以我错过了nasegae.py中的一行:
del sys.modules['google']
Which is fixed already to reload(sys.modules['google'])
已修复的问题可以
reload(sys.modules['google'])
https://github.com/Trii/NoseGAE/commit/82fe8b4cb2c037ffd441fa5bed8a6b84a066bbd2 https://github.com/Trii/NoseGAE/commit/82fe8b4cb2c037ffd441fa5bed8a6b84a066bbd2
The issue is gone. 问题不见了。
AttributeError: 'module' object has no attribute 'appengine'
AttributeError:“模块”对象没有属性“ appengine”
This suggests the GAE SDK is not properly located. 这表明GAE SDK的位置不正确。
Check your SDK installation/usage instructions, python path, directory structure, IDE settings (if you use one) - depending on how you're planning to use the SDK. 检查SDK的安装/使用说明,python路径,目录结构,IDE设置(如果使用的话)-取决于您打算如何使用SDK。
Also the unittest/mock instructions (I can't comment on them - haven't used them yet). 还有unittest / mock指令(我无法对其进行评论-尚未使用它们)。
You could try symlink-ing the 'google' SDK subdir in /Users/sadovnychi/example for example - but I can't tell if this is a good suggestion for your setup. 例如,您可以尝试将符号链接到/ Users / sadovnychi / example中的“ google” SDK子目录-但我无法确定这是否对您的设置是一个好建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.