ホームページ  >  に質問  >  本文

python - django error (unittest.loader._FailedTest),求大神解答。

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中文网2740日前1578

全員に返信(1)返信します

  • 巴扎黑

    巴扎黑2017-04-18 09:35:35

    一晩かけて勉強した結果、問題は解決しました。ご心配とご協力をいただきありがとうございます。
    主な質問が 3 つあります:
    最初のポイント: 問題は test.py にあります
    tests.py:

    リーリー

    2 番目のポイント: 上記の問題を解決した後、エラー ImportError: 名前 'patterns' をインポートできません
    解決策: urls.py を変更し、home_page をインポートします

    リーリー

    3 番目の点: これは私自身の認識です。Django 1.10 ではパターンは非推奨になりましたが、私は依然としてパターンを使用していました。また、これは非常に間違っています。また、公式ドキュメントもよく読んでいません。しっかり読んでいなかったので、とてもレベルの低い間違いをしてしまい、本当に恥ずかしいです。

    エラーと解決策の概要:

    リーリー

    関連質問の参考 URL:
    http://stackoverflow.com/ques...
    http://python.6.x6.nabble.com...

    返事
    0
  • キャンセル返事