简体   繁体   中英

django unittest import error

Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Users\mech10>cd superlists

C:\Users\mech10\superlists>python manage.py test
Creating test database for alias 'default'...
E
======================================================================
ERROR: lists.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: lists.tests
Traceback (most recent call last):
File "C:\Users\mech10\Anaconda3\lib\unittest\loader.py", line 428,in    _find_test_path
module = self._get_module_from_name(name)
File "C:\Users\mech10\Anaconda3\lib\unittest\loader.py", line 369, in _get_module_from_name__import__(name)
File "C:\Users\mech10\superlists\lists\tests.py", line 9
self.assertEqual(found.func,home_page)
                                     ^
TabError: inconsistent use of tabs and spaces in indentation


----------------------------------------------------------------------
Ran 1 test in 0.001s

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

tests.py

    from django.core.urlresolvers import resolve
    from django.test import TestCase
    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
from django.contrib import admin

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url(r'^$', 'lists.views.home_page', name='home'),
]

views.py

from django.shortcuts import render

def home_page():
  pass

I followed the instructions from a django test book but I don't understand why my test script doesn't work.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM