복붙노트

[PYTHON] PyCharm에서 Django 테스트 실행하기

PYTHON

PyCharm에서 Django 테스트 실행하기

PyCharm에서 간단한 Django 테스트를 실행하려고하는데, 다음 스택 추적으로 실패합니다.

/home/ramashishb/local/pyenv/testenv/bin/python /opt/pycharm-3.0.2/helpers/pycharm/django_test_manage.py test snippets.SimpleTest.test_simple /home/ramashishb/mine/learn/django-rest/django-rest-tutorial
Testing started at 4:37 PM ...
Traceback (most recent call last):
  File "/opt/pycharm-3.0.2/helpers/pycharm/django_test_manage.py", line 18, in <module>
    import django_test_runner
  File "/opt/pycharm-3.0.2/helpers/pycharm/django_test_runner.py", line 14, in <module>
    from django.test.testcases import TestCase
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/test/__init__.py", line 5, in <module>
    from django.test.client import Client, RequestFactory
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/test/client.py", line 11, in <module>
    from django.contrib.auth import authenticate, login, logout, get_user_model
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 6, in <module>
    from django.middleware.csrf import rotate_token
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/middleware/csrf.py", line 14, in <module>
    from django.utils.cache import patch_vary_headers
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/utils/cache.py", line 26, in <module>
    from django.core.cache import get_cache
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/core/cache/__init__.py", line 69, in <module>
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, 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

테스트는 - ./manage.py를 사용하여 콘솔에서 잘 실행됩니다. 테스트를 실행하기 전에는 설치가되지 않은 것 같습니다.

어떤 생각?

감사, 램

해결법

  1. ==============================

    1.메뉴 파일> 설정> Django 지원으로 이동하여 올바른 설정 파일을 선택하십시오.

    메뉴 파일> 설정> Django 지원으로 이동하여 올바른 설정 파일을 선택하십시오.

  2. from https://stackoverflow.com/questions/20399046/running-django-tests-in-pycharm by cc-by-sa and MIT license