Django的LiveServerTestCase总是因为地址冲突而失败,尽管地址出现了 [英] Django's LiveServerTestCase Always Fails Due to Conflicting Address... Despite Address Appearing Free

查看:267
本文介绍了Django的LiveServerTestCase总是因为地址冲突而失败,尽管地址出现了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在清理Django功能测试以使用LiveServerTestCase,而不是在后台运行的开发环境的一个实例上弹出基于硒的测试,我已经打了墙。每次我尝试运行一个LiveServerTestCase测试,我收到以下错误:

I'm currently working on cleaning my Django functional tests to use the LiveServerTestCase rather than bouncing selenium based tests off an instance of the development environment running in the background, and I've hit a wall. Every time I try to run a LiveServerTestCase test, I get the following error:

======================================================================
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

超级好玩,考虑 sudo netstat -netp | grep 8081 没有收到。有些背景:我正在使用Django 1.6,而我使用的是鼻子,鼻子鼻子,鼻子排除,但是我已经把它们切断了,以帮助诊断问题。我使用的代码非常简单:

Super fun, considering sudo netstat -netp | grep 8081 yields nothing. Some background: I'm using Django 1.6, and I was using nose, django-nose, nose-exclude, but I've effectively chopped them out to help diagnose the issue. The code I'm using is abysmally simple:

from django.test import LiveServerTestCase
class TestCmsLogin(LiveServerTestCase):
    def test_a_test_itself(self):
        self.assertTrue(True)

I在这个主题上找不到任何现有技术,Djangoproject的bug跟踪器是干净的。我缺少什么?

I can't find any prior art on the subject, and Djangoproject's bug tracker is clean. What am I missing?

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

This morning the issue is irreproducible, whatever was flagging port 8081 as open is no longer causing issues.

编辑2:在我的写作中,将8081作为8082,并将其固定(并检查以确保我在正确的时间)。

edit2: Mistyped 8081 as 8082 in my writeup, fixed (and checked to make sure I had it right at the time).

推荐答案

您可以设置(在settings.py中)环境变量 DJANGO_LIVE_TEST_SERVER_ADDRESS 包含将尝试的多个端口范围:

You can set (in settings.py) the environment variable DJANGO_LIVE_TEST_SERVER_ADDRESS to include multiple ranges of ports that will be attempted:

os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS']="localhost:8000-8010,8080,9200-9300"

自己有同样的问题,也许这有助于某人出去。

Had the same issue myself, maybe this helps someone out.

这篇关于Django的LiveServerTestCase总是因为地址冲突而失败,尽管地址出现了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆