21

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

SteveMustafa
  • 621
  • 2
  • 8
  • 19
  • You probably have multiple files that contain tests. On which suite does this error happen? – Ella Sharakanski Apr 24 '15 at 19:09
  • Do you mean py files that contain tests or do you mean test suites like nose and tox? – SteveMustafa Apr 24 '15 at 22:30
  • If you meant actual py files that contain tests, then no, its just the one file. But when I run my functional tests (in a different directory) there are no problems there. This has been the case for at least the last week and there were no problems all through out that time. – SteveMustafa Apr 24 '15 at 22:49
  • Does it happen if you delete that file that has tests? And run the command `python manage.py test` – Ella Sharakanski Apr 24 '15 at 22:57
  • Have you tried running it on another computer? – Ella Sharakanski Apr 24 '15 at 23:00
  • 1
    Hmmm.... I found something incredibly strange. If I run "python manage.py test list/" this works, but "python manage.py test list/tests.py" it blurts out that error message I pasted earlier... WHY? – SteveMustafa Apr 24 '15 at 23:03
  • 1
    I think you should use a dotted format. Try `python manage.py test list.tests` – Ella Sharakanski Apr 24 '15 at 23:11
  • @EllaShar Just to be clear, "list/" in the posts above defines a folder named "list" The actual file name is tests.py and it is within that folder; How can I adopt a dotted format with that in mind? Or perhaps a better question is what benefit is there? – SteveMustafa Apr 24 '15 at 23:14
  • 1
    See the docs. https://docs.djangoproject.com/en/1.8/topics/testing/overview/#running-tests The way you run your tests is invalid. The dotted format is valid. – Ella Sharakanski Apr 24 '15 at 23:18
  • @EllaShar point well made, thank you, I'll be doing so right now. This is marked as resolved. – SteveMustafa Apr 24 '15 at 23:32
  • I've had this happen when I had unsaved files in my Emacs. I checked the directory and my emacs created (invisible) backup files in an app's directory, e.g. `.#urls.py`. After deleting these files - or saving everything - the tests run fine. Very odd. – yerforkferchips Apr 11 '16 at 12:39

3 Answers3

44

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

Peter Ogden
  • 819
  • 8
  • 5
5

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

SteveMustafa
  • 621
  • 2
  • 8
  • 19
  • I had this exact same problem after upgrading Django and PyCharm. Using a path for the test target used to work but had the exact error you specified after the upgrade... I changed it to use the dot notation and it started working again. – John Q May 25 '15 at 19:39
0

For me, it was a Database issue.

Apparently, the run stopped in the middle and he did not have time to delete the DB of the tests.

Deleting the DB test solves the issue

Yinon_90
  • 1,315
  • 12
  • 17