2017-05-25 133 views
0

python3 manage.py測試apps.favoritesDjango的單元測試:類型錯誤: 'NoneType' 對象不是可迭代

Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_e 
    utility.execute() 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/core/management/commands/test.py", line 29, in run_v 
    super(Command, self).run_from_argv(argv) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute 
    output = self.handle(*args, **options) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/core/management/commands/test.py", line 72, in hande 
    failures = test_runner.run_tests(test_labels) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/test/runner.py", line 548, in run_tests 
    suite = self.build_suite(test_labels, extra_tests) 
    File "/home/dmitry/.pyenv/versions/p/lib/python3.5/site-packages/django/test/runner.py", line 466, in build_suite 
    tests = self.test_loader.discover(start_dir=label, **kwargs) 
    File "/home/dmitry/.pyenv/versions/3.5.1/lib/python3.5/unittest/loader.py", line 341, in discover 
    tests = list(self._find_tests(start_dir, pattern)) 
    File "/home/dmitry/.pyenv/versions/3.5.1/lib/python3.5/unittest/loader.py", line 406, in _find_tests 
    yield from self._find_tests(full_path, pattern, namespace) 
    File "/home/dmitry/.pyenv/versions/3.5.1/lib/python3.5/unittest/loader.py", line 398, in _find_tests 
    full_path, pattern, namespace) 
TypeError: 'NoneType' object is not iterable 
沒有細節非常隱蔽消息。一切都在昨晚工作。
apps/favorites 
├── admin.py 
├── api 
│   ├── __init__.py 
│   ├── mixins.py 
│   ├── permissions.py 
│   └── __pycache__ 
│    ├── __init__.cpython-35.pyc 
│    ├── mixins.cpython-35.pyc 
│    └── permissions.cpython-35.pyc 
├── apps.py 
├── __init__.py 
├── managers.py 
├── migrations 
│   ├── 0001_initial.py 
│   ├── __init__.py 
│   └── __pycache__ 
│    ├── 0001_initial.cpython-35.pyc 
│    └── __init__.cpython-35.pyc 
├── models.py 
├── __pycache__ 
│   ├── admin.cpython-35.pyc 
│   ├── apps.cpython-35.pyc 
│   ├── __init__.cpython-35.pyc 
│   ├── managers.cpython-35.pyc 
│   └── models.cpython-35.pyc 
└── tests 
    ├── __init__.py 
    ├── __pycache__ 
    │   ├── __init__.cpython-35.pyc 
    │   └── test_models.cpython-35.pyc 
    └── test_models.py 

7 directories, 24 files 
+0

向我們展示'apps.favorites'模塊。 –

+0

約翰,你的意思是一個test_models.py或? – DmitrySemenov

+0

請閱讀並遵循幫助文檔中的發佈準則。 [最小,完整,可驗證的示例](http://stackoverflow.com/help/mcve)適用於此處。在發佈您的MCVE代碼並準確描述問題之前,我們無法爲您提供有效的幫助。 我們應該能夠將發佈的代碼粘貼到文本文件中,並重現您描述的問題。 – Prune

回答

1

這通常發生在你預計列表(或其他序列)從函數返回,但得到的None空的結果。如果您隨後將此列表列入需要迭代的內容,例如簡單的for循環,則會顯示錯誤。例如:

>>> oops = None 
>>> for i in oops: 
...  print i 
... 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'NoneType' object is not iterable 
相關問題