2013-10-17 80 views
0

我已經安裝了一個尚未公開的源代碼第三方Django應用程序使用pip,現在我正在爲它執行單元測試。然而,每當我試圖運行單元測試,它會導致以下回溯每個測試用例:運行第三方Django應用程序的測試導致「ImportError:No module named urls」

ERROR: test_form_page_loads (myapp.tests.tests.ViewTests) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/sampling/tests/tests.py", line 47, in test_form_page_loads 
    response = self.client.get(self.form_url) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/test/client.py", line 453, in get 
    response = super(Client, self).get(path, data=data, **extra) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/test/client.py", line 271, in get 
    parsed = urlparse(path) 
    File "/usr/lib/python2.7/urlparse.py", line 135, in urlparse 
    tuple = urlsplit(url, scheme, allow_fragments) 
    File "/usr/lib/python2.7/urlparse.py", line 168, in urlsplit 
    cached = _parse_cache.get(key, None) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/utils/functional.py", line 156, in __hash__ 
    return hash(self.__cast()) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/utils/functional.py", line 139, in __cast 
    return self.__bytes_cast() 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/utils/functional.py", line 135, in __bytes_cast 
    return bytes(func(*self.__args, **self.__kw)) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 496, in reverse 
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 382, in _reverse_with_prefix 
    possibilities = self.reverse_dict.getlist(lookup_view) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 297, in reverse_dict 
    self._populate() 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 263, in _populate 
    for pattern in reversed(self.url_patterns): 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns 
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module 
    self._urlconf_module = import_module(self.urlconf_name) 
    File "/home/yiqing/repos/dotfiles/common/virtualenvwrapper_hooks/filer_demo/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module 
    __import__(name) 
ImportError: No module named urls 

下面是這個應用程序的目錄結構,在情況下,它是相關的:

myapp/ 
├── admin.py 
├── conf.py 
├── forms.py 
├── __init__.py 
├── models.py 
├── templates 
├── tests 
│   ├── __init__.py 
│   ├── models.py 
│   ├── settings.py 
│   └── tests.py 
├── urls.py 
└── views.py 

回答

0

原來我需要創建一個urls.py,其中包含myapp/tests/以內的根url conf-like設置。