如果我单独运行一次测试,但是如果我尝试测试整个课程,则第一次测试通过,而第二次测试则通过Server Error ( 500 )
,有两个测试都对用户进行了相同的记录。 >
所有测试都涉及user
登录,我尝试在每个测试中在本地创建用户,但均无济于事,不胜感激。
class SomeTest(StaticLiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(10)
self.user = User.objects.create_user(username="user1",password="somepassword")
self.user.save()
qrt, created = Group.objects.get_or_create(name="A Team")
qrt.user_set.add(self.user)
def tearDown(self):
self.browser.quit()
def test_user_can_login(self):
self.browser.get(self.live_server_url)
user = self.browser.find_element_by_id("id_username")
pa = self.browser.find_element_by_id("id_password")
user.send_keys("user1")
pa.send_keys("somepassword")
pa.send_keys(Keys.ENTER)
title = self.browser.find_element_by_id("title").text
self.assertIn(title, "Welcome")
def test_user_can_login_again(self):
self.browser.get(self.live_server_url)
user = self.browser.find_element_by_id("id_username")
pa = self.browser.find_element_by_id("id_password")
user.send_keys("user1")
pa.send_keys("somepassword")
pa.send_keys(Keys.ENTER)
title = self.browser.find_element_by_id("title").text
self.assertIn(title, "Welcome")