我已经使用pip安装了一个尚未开源的第三方Django应用程序,现在我正在为它实现单元测试。但是,每当我尝试运行单元测试时,它会导致每个测试用例的以下回溯:
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 :(得分:0)
事实证明,我需要在urls.py
内创建一个{urn-conf-like设置的myapp/tests/
。