Running Django tests in PyCharm

前端 未结 2 471
闹比i
闹比i 2020-12-05 17:34

I am trying to run a simple Django test in PyCharm, but its failing with the following stack trace-

/home/ramashishb/local/pyenv/testenv/bin/python /opt/pych         


        
相关标签:
2条回答
  • 2020-12-05 18:18

    Go to menu file > settings > Django Support and select correct settings file.

    enter image description here

    0 讨论(0)
  • 2020-12-05 18:28

    I was experiencing the same problem. I found that I was running the wrong type of test.

    import unittest
    class MySampleTest(unittest.TestCase):
    

    Cause the error

    django.core.exceptions.ImproperlyConfigured: Requested setting API_BASE_URL, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
    

    Changing to the import to

    from django.test import SimpleTestCase
    
    Class MySampleTest(SimpleTestCase):
    

    allowed my test to run from within pycharm.

    0 讨论(0)
提交回复
热议问题