2017-12-29 45 views
1

환경 : 인 IntelliJ PyCharm, 파이썬 장고, 장고 유닛 테스트 오류로 실행

내가 표준 장고 설치 프로젝트를 사용 sqlite3를

. Unittest를 작성하려고하는데 다음과 같은 오류가 발생합니다. 약간의 연구 끝에, 나는 여기서 끝났다. tests.py

from django.test import TestCase as djangoTestCase 
import os 
import unittest 

# Create your tests here. 
class TestExample(djangoTestCase): 

    def setUp(self): 
     print('setup') 
     print(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 

    def test_abc(self): 
     self.assertEqual(1,1) 

    def tearDown(self): 
     print('tearDown') 

if __name__ == '__main__': 
    unittest.main() 

이의

DB 구성

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 

코드는 내가 노력

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. 

출력입니다 문서를 읽음으로써 실수를 찾지 만 성공하지 못합니다. 무엇이 문제 일 수 있습니까? 장고와

+1

테스트를 어떻게 실행합니까? 쉘에서'python manage.py test'가 작동합니까? – Alasdair

+0

예, 잘 작동합니다. PyCharm과 약간의 경험이 있습니까? 테스트를 시작하면 설명 된 오류가 발생합니다. –

+0

죄송합니다. PyCharm 구성을 도와 드릴 수 없습니다. – Alasdair

답변

1

는이 부분이 필요하지 않습니다 테스트 : 당신은 그냥 python manage.py test 명령을 사용하여 테스트를 실행

if __name__ == '__main__': 
    unittest.main() 

.

+0

좋습니다, 감사합니다. 그것은 cmd 명령으로 작동하지만 PyCharm에서 -> Test로는 작동하지 않습니다. –

+0

Pycharm에서 Run/Debug cunfiguration을 추가해야합니다. 스크립트'manage.py' 파일로 선택하십시오. 스크립트 매개 변수로'test'를 지정하십시오. – neverwalkaloner

+0

이 문서 확인 : https://www.jetbrains.com/help/pycharm/creating-and-editing-run-debug-configurations.html – neverwalkaloner