2015-04-17 45 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模塊訪問問題。我懷疑有些鼻子多處理器配置/設置丟失,但我對此一無所知。 –