django.core.exceptions.ImproperlyConfigured:请求的设置为INSTALLED_APPS,但未配置设置。您必须先定义环境变量DJANGO_SETTINGS_MODULE或调用settings.configure()才能访问设置。
我的功能测试:
from selenium import webdriver
from lists.models import Item
from selenium.webdriver.common.keys import Keys
import time
import unittest
import os
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('http://localhost:8000/')
# She notices the page title and header mention to-do lists
print(self.browser.title)
self.assertIn('lists', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('list', header_text)
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertEqual(
inputbox.get_attribute('placeholder'),
'Enter a to-do item'
)
inputbox.send_keys('Buy peacock feathers')
inputbox.send_keys(Keys.ENTER)
time.sleep(1)
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertIn('1: Buy peacock feathers',[row.text for row in rows])
self.assertIn('2: Use a peacock feather', [row.text for row in rows])
self.fail('Finish the test!')
def check_for_row_in_list_table(self,row_text):
table = self.browser.find_element__by_id('id_list_table')
rows = table.find_element_by_tag_name('tr')
self.assertIn(row_text,[row.text for row in rows])
inputbox.send_keys(Keys.ENTER)
time.sleep(1)
self.check_for_row_in_list_table('1:Buy a peacock feather')
inputbox = self.browser.find_element_by_id('id_new_item')
input.send_keys('Use peacock feathers to make a fly')
inputbox.send_keys(Keys.ENTER)
time.sleep(1)
self.check_for_row_in_list_table('1:Buy a peacock feather')
self.check_for_row_in_list_table('2: Use a peacock feather')
if __name__ == '__main__':
unittest.main(warnings='ignore')
我的模型:当我尝试运行functional_tests时,出现错误。
from django.db import models
class Item(models.Model):
text = models.TextField(default='')
我的设置文件。我也将列表应用程序包含在我的INSTALLED_APPS中。
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'xyz'
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lists.apps.ListsConfig',
]
最佳答案
从文件中删除from lists.models import Item
,模型Item
未使用