如何使用本地设置在Django中使用PyCharm以调试模式运行python单元测试?

如何使用本地设置在Django中使用PyCharm以调试模式运行python单元测试?,python,django,unit-testing,intellij-idea,pycharm,Python,Django,Unit Testing,Intellij Idea,Pycharm,我的Django项目有本地设置。我使用/manage.py runserver--settings=settings.local命令运行应用程序 我对Unittests 但是当我为test.t按Debug Unittests时,我得到了错误 /home/m0nte-cr1st0/.virtualenvs/onedeeds/bin/python /home/m0nte-cr1st0/.local/share/umake/ide/pycharm/helpers/pycharm/_jb_unitte

我的
Django
项目有本地设置。我使用
/manage.py runserver--settings=settings.local
命令运行应用程序

我对
Unittests

但是当我为test.t按Debug Unittests时,我得到了错误

/home/m0nte-cr1st0/.virtualenvs/onedeeds/bin/python /home/m0nte-cr1st0/.local/share/umake/ide/pycharm/helpers/pycharm/_jb_unittest_runner.py --target core.test.test_views.ReactivateAccountViewTestCase
Launching unittests with arguments python -m unittest core.test.test_views.ReactivateAccountViewTestCase in /home/m0nte-cr1st0/pet_projects/onedeeds/onedeeds/core

Traceback (most recent call last):
  File "/home/m0nte-cr1st0/.local/share/umake/ide/pycharm/helpers/pycharm/_jb_unittest_runner.py", line 35, in <module>
    main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING)
  File "/usr/local/lib/python3.7/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/usr/local/lib/python3.7/unittest/main.py", line 147, in parseArgs
    self.createTests()
  File "/usr/local/lib/python3.7/unittest/main.py", line 159, in createTests
    self.module)
  File "/usr/local/lib/python3.7/unittest/loader.py", line 220, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/local/lib/python3.7/unittest/loader.py", line 220, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/local/lib/python3.7/unittest/loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "/home/m0nte-cr1st0/pet_projects/onedeeds/onedeeds/core/test/test_views.py", line 6, in <module>
    from rest_framework.authtoken.models import Token
  File "/home/m0nte-cr1st0/.virtualenvs/onedeeds/lib/python3.7/site-packages/rest_framework/authtoken/models.py", line 9, in <module>
    class Token(models.Model):
  File "/home/m0nte-cr1st0/.virtualenvs/onedeeds/lib/python3.7/site-packages/rest_framework/authtoken/models.py", line 15, in Token
    settings.AUTH_USER_MODEL, related_name='auth_token',
  File "/home/m0nte-cr1st0/.virtualenvs/onedeeds/lib/python3.7/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/home/m0nte-cr1st0/.virtualenvs/onedeeds/lib/python3.7/site-packages/django/conf/__init__.py", line 64, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, 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
设置/local.py

AUTH_USER_MODEL = "core.User"
from .base import *
项目结构

onedeeds/
  onedeeds/
    app1/
      ...
      test/
    app2/
      ...
      test/
    settings/
      base.py
      local.py
    manage.py

您使用的是pycharm社区还是专业?您使用的是默认的测试运行程序还是pytest?@MattSeymour我使用的是
PyCharm社区Edtion 2019.1.3
。对于测试,我使用
/manage.py test
您确定您的屏幕截图是针对单元测试运行配置的吗?它看起来和我的不一样(虽然我没有使用community edition。你的文件名是“OneDects”。这里面真的只有单元测试吗?DJANG0_设置_模块中有一个零,你应该有一个“哦”。比如,“哦,天哪,我不应该手工输入环境变量名。”!@БМицициццицициццицццццццццццц109。