Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suddenly when running tests I get "TypeError: 'NoneType' object is not iterable

Tags:

This is phenomenally strange for me, things were working PERFECTLY fine until this morning.

When I attempt to run my unit test using the following (I have Python3 soft linked to python)

clear; python manage.py test list tests/  

I now get the following error message:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.4/site-packages/django/core/management        /__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.4/site-packages/django/core/management        /__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.4/site-packages/django/core/management/commands    /test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/usr/lib/python3.4/site-packages/django/core/management    /base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python3.4/site-packages/django/core/management/commands    /test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/usr/lib/python3.4/site-packages/django/core/management    /base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.4/site-packages/django/core/management/commands    /test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/usr/lib/python3.4/site-packages/django/test/runner.py", line     146, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/usr/lib/python3.4/site-packages/django/test/runner.py", line     101, in build_suite
    suite.addTests(tests)
  File "/usr/lib64/python3.4/unittest/suite.py", line 60, in addTests
    for test in tests:
TypeError: 'NoneType' object is not iterable

I initially thought that I wrote something that completely messed everything up, so I saved this as a branch, reverted back in the master branch to a commit that I am CERTAIN works but I get the exact same error message.

I can't think of anything I did to make things fail like this, in fact, the above doesn't point to anything I've written which (in my case, I'm relatively new to Python/Django) is making it difficult for me to debug the error.

The ONLY thing I can think of that changed is my installation of The Silver Searcher (I use vim) which I removed and still the same error happens.

I've reinstalled django, but still to no avail.

This is on:

  • OpenSuse 13.2
  • Django 1.7
  • Python 3.4.1

Can someone help me out in

  • debugging the cause of this error (so that I don't fall in it again)
  • how to go about fixing this?

Thank you

like image 947
SteveMustafa Avatar asked Apr 24 '15 18:04

SteveMustafa


People also ask

How do I fix this TypeError NoneType object is not iterable?

The TypeError: 'NoneType' object is not iterable error is raised when you try to iterate over an object whose value is equal to None. To solve this error, make sure that any values that you try to iterate over have been assigned an iterable object, like a string or a list.

How do you solve a TypeError argument of type NoneType is not iterable?

The Python "TypeError: argument of type 'NoneType' is not iterable" occurs when we use the membership test operators (in and not in) with a None value. To solve the error, correct the assignment of the variable that stores None or check if it doesn't store None .

What does TypeError NoneType object is not iterable?

The Python "TypeError: 'NoneType' object is not iterable" occurs when we try to iterate over a None value. To solve the error, figure out where the variable got assigned a None value and correct the assignment or check if the variable doesn't store None before iterating.


2 Answers

Just had this error, caused by an issue I had solved months ago and accidentally happened upon briefly again.

The problem is that when you specify the directory for django test you should use python notation for the directory, not standard shell notation. For example

Correct - project.tests.test_module

Incorrect - project/tests/test_module.py

like image 148
Peter Ogden Avatar answered Sep 21 '22 16:09

Peter Ogden


I wasn't able to explain WHY this is so, but when I ran the "python manage.py test list/" without specifying the file name, things worked perfectly well.

Thanks to user Ella Shar, I will be changing the scheme/layout I set my tests to the approved dotted format as described in the documentation

like image 31
SteveMustafa Avatar answered Sep 20 '22 16:09

SteveMustafa