No tests were found - Pycharm + Django

Completed

Can anyone help with this (is this the right place to ask this kind of question)? Pycharm is telling me 'No tests were found" when I try to test my code in a Django project. 

PyCharm version 2017.2.3

Here's my code:

# test_models.py
# from django.test import TestCase
# import balancer.models
import unittest

class Dictfetchall(unittest.TestCase):

    def test_no_recs(self):
    self.assertEqual(True, False)

 

Note that I commented out the django-specific stuff just to get it to run from the command line (which it does). 

Here is the stack trace:

Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 157, in <module>
utility.execute()
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 132, in execute
PycharmTestCommand().run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 97, in handle
failures = TestRunner(test_labels, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 256, in run_tests
extra_tests=extra_tests, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 156, in run_tests
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/test/runner.py", line 531, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 120, in build_suite
suite = super(DjangoTeamcityTestRunner, self).build_suite(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/test/runner.py", line 457, in build_suite
suite.addTests(tests)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/suite.py", line 57, in addTests
for test in tests:
TypeError: 'NoneType' object is not iterable

Process finished with exit code 1
Empty test suite.

Thank you,

Ben

0
1 comment

I figured this out so, in hopes that it helps someone else, here's what I did (also documented here in StackOverflow)...

I originally deleted the standard Django file tests.py out of my application folder. I also created a subdirectory of my project called tests, which contains separate test scripts. In this situation, Pycharm failed to find the tests. I corrected this simply by creating an empty file called tests.py in my application folder.

So:

  1. Make sure you have a file called tests.py in your application director (it can be an empty file)
  2. It seems that a folder called tests, in your project, can contain separate test scripts and Pycharm seems to find and run these.

Here's a picture of the directory structure that's working for me:

 

1

Please sign in to leave a comment.