相关疑难解决方法(0)

由于地址冲突,Django的LiveServerTestCase总是失败...尽管地址显得空闲

我正在努力清理我的Django功能测试以使用LiveServerTestCase,而不是在背景中运行的开发环境的实例上反弹基于selenium的测试,而且我已经碰壁了.每次我尝试运行LiveServerTestCase测试时,都会收到以下错误:

======================================================================
ERROR: setUpClass (fun_tests.tests.backend.TestCmsLogin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/user/Documents/env/local/lib/python2.7/site-packages/django/test/testcases.py", line 1187, in setUpClass
    raise cls.server_thread.error
error: [Errno 98] Address already in use
Run Code Online (Sandbox Code Playgroud)

超级好玩,考虑到sudo netstat -netp | grep 8081没有收益.一些背景:我正在使用Django 1.6,我使用鼻子,django-nose,鼻子排除,但我已经有效地将它们切掉以帮助诊断问题.我正在使用的代码非常简单:

from django.test import LiveServerTestCase
class TestCmsLogin(LiveServerTestCase):
    def test_a_test_itself(self):
        self.assertTrue(True)
Run Code Online (Sandbox Code Playgroud)

我找不到关于这个主题的任何现有技术,Djangoproject的bug追踪器很干净.我错过了什么?

编辑:今天早上这个问题是不可复制的,无论是标记端口8081,因为打开不再导致问题.

edit2:在我的写作中将8081误导为8082,修复(并检查以确保我当时正确).

python django

15
推荐指数
2
解决办法
3109
查看次数

跨 LiveServerTestCase 测试方法保留数据?

因为LiveServerTestCase继承自TransactionTestCase,默认行为是在每个测试方法结束时删除测试数据。我想使用LiveServerTestCase该类,但保留方法与方法之间的测试数据。在本例中,test2失败是因为数据库在test1.

我的理解是,如果我使用TestCase,它会在每次测试结束时回滚事务并将数据库返回到其起始条件。我可以在使用 时模仿这种行为LiveServerTestCase吗?

class TestTheTests(LiveServerTestCase):

    @classmethod
    def setUpTestData(cls):
        print('running setUpTestData')
        call_command('loaddata', 'datasources.yaml' )

    @classmethod
    def setUpClass(cls):
        print('starting setUpClass')
        cls.setUpTestData() # load the data for the entire test class
        super().setUpClass()

    @classmethod
    def tearDownClass(cls):
        print('finished tearDownClass')
        super().tearDownClass()

    def setUp(self):
        self.browser = webdriver.Chrome()

    def tearDown(self):
        self.browser.quit()
Run Code Online (Sandbox Code Playgroud)

当我同时运行这两个测试时,此测试通过:

    def test1(self):
        print('test 1 running')
        self.assertEquals(8, DataSource.objects.count(),'There should be 8 DataSource objects in test1')
Run Code Online (Sandbox Code Playgroud)

此测试失败:

    def test2(self):
        print('test 2 running')
        self.assertEquals(8, DataSource.objects.count(),'There …
Run Code Online (Sandbox Code Playgroud)

python django unit-testing

7
推荐指数
1
解决办法
358
查看次数

标签 统计

django ×2

python ×2

unit-testing ×1