2015-04-17 22 views
1

给定一个测试用例:进口不妥善处理,同时运行在多进程nosetests模式

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'] 

任何想法,为什么它的发生,以及如何要解决这个问题?

回答

0

AttributeError: 'module' object has no attribute 'appengine'

这表明GAE SDK没有正确定位。

检查您的SDK安装/使用说明,Python路径,目录结构,IDE设置(如果使用的话) - 取决于您打算如何使用SDK。

单元测试/模拟指令(我不能评论他们 - 还没有使用它们)。

您可以尝试在/ Users/sadovnychi/example中的'google'SDK子目录符号链接 - 但我无法确定这是否是您的设置的好建议。

+0

当然,我已经检查了您提到的所有内容,并且它的工作正常,关闭了多处理功能。 –

+0

啊,我错过了那个方面。但事实上,它基本上是一个SDK模块访问问题。我怀疑有些鼻子多处理器配置/设置丢失,但我对此一无所知。 –