Hak*_* B. 11 python django selenium django-testing
我正在使用Django 1.4的LiveServerTestCase进行Selenium测试,并且遇到了setUpClass类方法的问题.据我所知MembershipTests.setUpClass,在单元测试运行之前运行一次.
我已经将代码添加到数据库中,MembershipTests.setUpClass但是当我运行MembershipTests.test_signup测试时,没有用户添加到测试数据库中.我做错了什么?我希望我创建的用户setUpClass可以在所有单元测试中使用.
如果我将用户创建代码放入MembershipTests.setUp并运行,MembershipTests.test_signup我可以看到用户,但不希望在每个单元测试之前运行setUp.如您所见,我使用自定义LiveServerTestCase类在我的所有测试中添加基本功能(test_utils.CustomLiveTestCase).我怀疑这与我的问题有关.
提前致谢.
test_utils.py:
from selenium.webdriver.firefox.webdriver import WebDriver
from django.test import LiveServerTestCase
class CustomLiveTestCase(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.wd = WebDriver()
super(CustomLiveTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.wd.quit()
super(CustomLiveTestCase, cls).tearDownClass()
Run Code Online (Sandbox Code Playgroud)
tests.py:
from django.contrib.auth.models import User
from django.test.utils import override_settings
from test_utils import CustomLiveTestCase
from test_constants import *
@override_settings(STRIPE_SECRET_KEY='xxx', STRIPE_PUBLISHABLE_KEY='xxx')
class MembershipTests(CustomLiveTestCase):
fixtures = [
'account_extras/fixtures/test_socialapp_data.json',
'membership/fixtures/basic/plan.json',
]
def setUp(self):
pass
@classmethod
def setUpClass(cls):
super(MembershipTests, cls).setUpClass()
user = User.objects.create_user(
TEST_USER_USERNAME,
TEST_USER_EMAIL,
TEST_USER_PASSWORD
)
def test_signup(self):
print "users: ", User.objects.all()
Run Code Online (Sandbox Code Playgroud)
小智 11
由于您使用的是LiveServerTestCase,因此它几乎与TransactionTestCase相同,后者为每个运行的测试用例创建和销毁数据库(截断表).
所以你真的无法用LiveServerTestCase做全局数据.
| 归档时间: |
|
| 查看次数: |
3669 次 |
| 最近记录: |