Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm django tests settings

Having troubles running tests in PyCharm.

manage.py test works fine.

But if I run test in PyCharm Django Test getting following error:

AttributeError: 'module' object has no attribute 'ROOT_URLCONF'

Django tests Run\Debug configuration:

DJANGO_SETTINGS_MODULE=project.settings.test

Django Preferences

Settings: project/settings/test.py

Manage Script: project/manage.py

Test

from django.test import SimpleTestCase
from rest_framework import status


class AccountTestCase(SimpleTestCase):

    def test_current_account(self):
        url = '/api/accounts/current/'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_301_MOVED_PERMANENTLY)

StackTrace

Error
    packages/django/core/handlers/base.py", line 113, in get_response
urlconf = settings.ROOT_URLCONF
  File "/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
return getattr(self._wrapped, name)
  File "/lib/python2.7/site-packages/django/conf/__init__.py", line 173, in __getattr__
return getattr(self.default_settings, name)
AttributeError: 'module' object has no attribute 'ROOT_URLCONF'

Would appreciate any help.

like image 717
Vladimir Nani Avatar asked Nov 22 '16 20:11

Vladimir Nani


People also ask

How do I enable Django in PyCharm?

To enable Django support, follow these steps: Open the project Settings/Preferences dialog ( Ctrl+Alt+S ) and navigate to the Languages & Frameworks | Django page. Make sure that the checkbox Enable Django support is selected. Apply changes (if any) and close the dialog.

How does PyCharm detect Django?

If you cannot print the Django version from the python console in Pycharm, go to settings>Project:project_name>project Interpreter and from the list of installed packages see the installed Django and it's version for that project.

How do I set the default test runner in PyCharm?

To set a test runner, press Ctrl+Alt+S to open the IDE settings and select Tools | Python Integrated Tools, and then select the target test runner from the Default test runner list.

Is PyCharm good for Django?

One of the features of PyCharm is that it includes a support for Django. With the ability of including JavaScript features within PyCharm, it can be considered as the best IDE for Django.


1 Answers

Ok got it.

You have to mark root folder in PyCharm as "sources root"

enter image description here

enter image description here

Then I guess it adds it to PYTHONPATH

like image 51
Vladimir Nani Avatar answered Oct 06 '22 02:10

Vladimir Nani