0
votes

I followed this tutorial https://docs.djangoproject.com/en/3.0/intro/tutorial05/

The tests can be run by the command (polls is the application name)

python manage.py test polls

However under PyCharm IDEA, when I click on the green arrow (line 21-22).

The message is "No tests were found"

enter image description here

The stack trace is gibberish to me

Traceback (most recent call last): File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pycharm/_jb_unittest_runner.py", line 35, in sys.exit(main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING)) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/main.py", line 100, in init self.parseArgs(argv) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/main.py", line 147, in parseArgs self.createTests() File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/main.py", line 159, in createTests self.module) File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/loader.py", line 220, in loadTestsFromNames suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/loader.py", line 220, in suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/loader.py", line 154, in loadTestsFromName module = import(module_name) File "/Users/raychenon/Projects/python/django/mysite/polls/test_views.py", line 8, in from .models import Question File "/Users/raychenon/Projects/python/django/mysite/polls/models.py", line 8, in class Question(models.Model): File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 107, in new app_config = apps.get_containing_app_config(module) File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 252, in get_containing_app_config self.check_apps_ready() File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 134, in check_apps_ready settings.INSTALLED_APPS File "/usr/local/lib/python3.7/site-packages/django/conf/init.py", line 76, in getattr self._setup(name) File "/usr/local/lib/python3.7/site-packages/django/conf/init.py", line 61, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Process finished with exit code 1

Empty suite

PyCharm IDE setup

My python interpreter is set correctly enter image description here

Research

I already looked at Pycharm - no tests were found? . Unrelated error, my test functions names start by test_*

2
Have you setup your python interpreter properly?James Lin
Of course, James, my IDE can run Python but it doesn't find the Django dependenciesRaymond Chenon
That means your interpreter has not been setup properly.James Lin

2 Answers

1
votes

Based on your comment saying your django dependencies cannot be found, I suspect you didn't setup the python interpreter properly for your project.

Eg. if you use virtualenv, you need to setup your python interpreter to point to the python bin inside your virtualenv, so Pycharm can find your packages.

Eg. photo below shows the python interpreter for my "pmas" virtualenv.

enter image description here

enter image description here

0
votes

can you try

export DJANGO_SETTINGS_MODULE=mysites.settings

here, mysites is name of Django project where settings.py is available

paste the above line in bash shell before running standalone python script