Django's LiveServerTestCase Always Fails Due to Conflicting Address… Despite Address Appearing Free

前端 未结 5 1207
心在旅途
心在旅途 2020-12-31 05:45

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 envi

5条回答
  •  感情败类
    2020-12-31 06:12

    If environment variable DJANGO_LIVE_TEST_SERVER_ADDRESS is not set the default address to start the live test server is localhost:8081. See LiveServerTestCase src code.

      # Launch the live server's thread
        specified_address = os.environ.get(
            'DJANGO_LIVE_TEST_SERVER_ADDRESS', 'localhost:8081')
    

    As the OS seems to be complaining about the port 8081 being in use. One can quickly pick another port (say 9000) by running the tests like below.

    /manage.py test functional_tests --liveserver :9000
    

    However, explicitly setting the DJANGO_LIVE_TEST_SERVER_ADDRESS would be ideal.

    export DJANGO_LIVE_TEST_SERVER_ADDRESS="localhost:9000"
    

提交回复
热议问题