2017-08-10 22 views
0

我是Java的新手。我得到了我認爲嘗試在Pycharm項目中使用Django類的類路徑問題。我如何讓我的項目識別django.contrib.auth.models包?如何使用Pycharm來檢查使用Django和docker-compose的測試?

以下是錯誤消息我得到:

/usr/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 49963 --file /Users/tcl/_myproject/workspace/myprojectapi/django-nonrel/myproject/integration_tests/tests/bulk_import_validation.py 
pydev debugger: process 4747 is connecting 

Connected to pydev debugger (build 172.3317.103) 
Traceback (most recent call last): 
    File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1596, in <module> 
    globals = debugger.run(setup['file'], None, None, is_module) 
    File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1023, in run 
    pydev_imports.execfile(file, globals, locals) # execute the script 
    File "/Users/tcl/_myproject/workspace/myprojectapi/django-nonrel/myproject/integration_tests/tests/bulk_import_validation.py", line 1, in <module> 
    from django.contrib.auth.models import User 
ImportError: No module named django.contrib.auth.models 

Process finished with exit code 1 

我得到這個錯誤試圖通過對類右擊並選擇調試運行在Pycharm一個測試類。

測試通常由使用該CMD線運行:

搬運工-撰寫運行myproject_api蟒manage.py測試integration_tests --configuration =開發。

有沒有辦法使用Pycharm調試器來逐步通過此代碼?

+0

你們是不是要直接從Django項目運行的腳本?有一個'manage.py'可以幫助你運行你的項目。 –

+0

我正在運行,右鍵單擊PyCharm中的test.py文件並選擇Debug。 – John

回答

1

當您直接運行測試時,django未加載。

您需要右鍵單擊manage.py並在配置中添加參數「test」。

在命令行上,可以執行python manage.py test

也可以執行指示經由點表示法,例如測試用例的特定測試案例

python manage.py test MYAPP.tests.MYTESTCASE

有關詳細信息,請查看Django文檔:https://docs.djangoproject.com/en/1.11/topics/testing/overview/#running-tests

+0

這是從cmd行運行的內容:docker-compose run myproject_api python manage.py test integration_tests --configuration = Dev。有沒有辦法使用Pycharm調試器來逐步通過這個代碼? – John

相關問題