Error when trying to run tests for python/django

I am writing tests for a django program and I keep getting this error when I run it through the command line (Windows): django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.


When I try running one of the test functions through PyCharm it says: Error running 'Unittests for test_models.UserTest': Can't get importable name for Is it a python file in project?


I know the problem has something to do with configuration settings, but I don't understand how to set these up properly.  I'm relatively new to PyCharm (and coding, in general) so any help would be much appreciated.  Thank you.



Ensure that Django support is enabled and configured in **File | Settings | Languages & Frameworks | Django**.

If still not working, add environment variable `DJANGO_SETTINGS_MODULE ` in your run configuration, and set the value to the dotted path to your

Try to create and run Django configuration, also try running using "Tools > task" and use "runserver".


Thank you for the reply.

When I go to File | Settings | Languages & Frameworks there is no Django option.  the only choices are 1) Schemas and DTD's or 2) Jupyter Notebook.  I'm using the community edition of PyCharm.

I set the environment variable to what you indicated.  When I try to run tests from PyCharm now, it doesn't give me an error, but it says no tests were found, ran 0 tests.  But my test file has 300 lines.


I don't understand what you mean by creating and running Django configuration.   When I go to tools, I don't see anything about task.

Sorry for all the questions.  I've used PyCharm before but not for in large-scale coding projects where I am running tests.  Thanks again for the help.   I can post screenshots or code snippets if that will help.


Oh, I see. If there's no Django settings, you're probably using Community edition of PyCharm, which don't have Django support.

You mentioned that you have the error when running from command line, so the issue is most likely not specific to IDE. You might also try asking on Stackoverflow or Django communities.


Okay, I will do that.  Thank you.


Please sign in to leave a comment.