python - django error (unittest.loader._FailedTest),求大神解答。
PHP中文网
PHP中文网 2017-04-18 09:33:35
0
1
1607

ERROR:

[lau@192 superlists]$ python manage.py test
Creating test database for alias 'default'...
E
======================================================================
ERROR: lau.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: lau.tests
Traceback (most recent call last):
File "/home/lau/anaconda3/lib/python3.5/unittest/loader.py", line 428, in _find_test_path
module = self._get_module_from_name(name)
File "/home/lau/anaconda3/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/home/lau/PycharmProjects/python core/superlists/lau/tests.py", line 3, in <module>
from lists.views import home_page
File "/home/lau/anaconda3/lib/python3.5/site-packages/lists.py", line 7, in <module>
def print_list (the_list, indent = false, level = 0):
NameError: name 'false' is not defined
----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
Destroying test database for alias 'default'...

tests.py:

from django.test import TestCase
from django.core.urlresolvers import resolve
from lists.views import home_page

class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
    found = resolve('/')
    self.assertEqual(found.func,home_page)

urls.py

from django.conf.urls import url,patterns,include
from django.contrib import admin
urlpatterns = ['',
url(r'^admin/', admin.site.urls),
url(r'^$', 'lau.views.home_page', name='home'),]

views.py

from django.shortcuts import render
def home_page():
pass

不管怎么修改都是ERROR: lau.tests (unittest.loader._FailedTest)
google了很久,只看到一个类似的
原答案:I have found my mistake. I started to use backspace for all the lines and clear all the irrelevant spaces in tests.py and the problem is solved now.
我真的费解死了,解决的让人摸不着头脑,祈求大神解答,谢谢,小白再次谢过。

PHP中文网
PHP中文网

认证高级PHP讲师

全部回覆(1)
巴扎黑

謝謝各位的關心幫助,研究了一整晚,問題已經解決。
我的問題主要有三點:
第一點:問題在tests.py裡
tests.py:

from django.test import TestCase
from django.core.urlresolvers import resolve
***from lists.views import home_page***
class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertEqual(found.func,home_page) 
——————————————————————————————————————————————————————  
from lists.views import home_page 这段代码应该改成
from lau.views import homepage,因为使用的书籍按部就班,所以导致这种低级错误。

第二點:解決上述問題後,出現 ImportError: cannot import name 'patterns'錯誤
解決方法:在urls.py中進行修改,導入home_page

from django.conf.urls import include,url
from django.contrib import admin
from lau.views import home_page
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', home_page),

第三點:這是我自己的一點感悟,在django1.10中,pattern被棄用,但我還是使用了pattern,這是非常不對的,加上我看東西不認真,官方文檔也沒有讀通,出現這種低級錯誤,實在慚愧。

總結錯誤和解決方法:

 ImportError: cannot import name 'patterns'
 解决方法:弃用patterns
 TypeError: view must be a callable or a list/tuple in the case of include().
 解决方法:导入home_page模块即可解决
 SyntaxError: trailing comma not allowed without surrounding parentheses
 解决方法:检查import处标点符号
 ERROR:unittest,loader.FailedTest
 解决办法:检查tests.py文件引入是否正确,检查文件是否有空格。

參考的相關問題網址:
http://stackoverflow.com/ques...
http://python.6.x6.nabble.com...

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板