1
我試圖用標準django測試來連接生菜。生菜在自己工作時工作正常。但是,當我從django.test.client導入客戶端時,出現錯誤: 「設置無法導入,因爲環境變量DJANGO_SETTINGS_MODULE未定義。」用django測試設置生菜的錯誤
我steps.py樣子:
from lettuce import *
from django.test.client import Client
@before.all
def set_browser():
world.browser = Client()
@step(r'I access the url "(.*)"')
def have_the_number(step,url):
world.response = world.browser.get(url)
我收到以下錯誤
File "/usr/local/bin/lettuce", line 9, in <module>
load_entry_point('lettuce==0.1.34', 'console_scripts', 'lettuce')()
File "/Library/Python/2.7/site-packages/lettuce-0.1.34-py2.7.egg/lettuce/lettuce_cli.py", line 71, in main
result = runner.run()
File "/Library/Python/2.7/site-packages/lettuce-0.1.34-py2.7.egg/lettuce/__init__.py", line 114, in run
self.loader.find_and_load_step_definitions()
File "/Library/Python/2.7/site-packages/lettuce-0.1.34-py2.7.egg/lettuce/fs.py", line 42, in find_and_load_step_definitions
module = __import__(to_load)
File "/Users/aliahsan/djcode/drftest/features/steps.py", line 2, in <module>
from django.test.client import Client
File "/Library/Python/2.7/site-packages/django/test/__init__.py", line 5, in <module>
from django.test.client import Client, RequestFactory
File "/Library/Python/2.7/site-packages/django/test/client.py", line 27, in <module>
from django.db import transaction, close_connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
我試圖設置DJANGO_SETTINGS_MODULE變量初始化 .py文件,但它不工作。 有人可以幫助我嗎?