Binding LiveServerTestCase bind to port 0

157 views
Skip to first unread message

Tim Graham

unread,
Jun 16, 2016, 9:23:05 PM6/16/16
to Django developers (Contributions to Django itself)
In IRC the other day, Donald pointed out https://www.dnorth.net/2012/03/17/the-port-0-trick/ and suggested that Django might be able to take advantage of that technique.

I put together a proof of concept that seems to work: https://github.com/django/django/pull/6791

I'm wondering if anyone sees any problems with this approach and if there's any use case for continuing to support customizing the address using the DJANGO_LIVE_TEST_SERVER_ADDRESS environment variable.

Daryl

unread,
Jun 16, 2016, 9:57:17 PM6/16/16
to django-d...@googlegroups.com
Wow : +8 −100 for that commit - that's a great re-factoring :)

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/148d1019-0e5b-4078-88f0-74adc92db08e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



charettes

unread,
Jun 16, 2016, 11:09:06 PM6/16/16
to Django developers (Contributions to Django itself)
I've never personally used DJANGO_LIVE_TEST_SERVER_ADDRESS for another purpose than preventing port conflicts which binding to port 0 solves.

It always looked strange to me to rely on an environment variable to achieve this. It feels like it was done this way to avoid introducing yet another setting.

I suppose we could deprecate DJANGO_LIVE_TEST_SERVER_ADDRESS and use
a LiveServerTestCase.server_thread_class = LiveServerThread attribute to create the thread and suggest overriding it in the deprecation warning message if new behavior is problematic.

Simon

Tim Graham

unread,
Jun 21, 2016, 11:35:06 AM6/21/16
to Django developers (Contributions to Django itself)
I'm inclined to make the changes, skip the deprecation, and react appropriately if anyone raises a use case that can't be achieved with the new "bind to port 0" technique.

I found a few more things that could be removed, for example the "manage.py test --liveserver=..." option. Only creating a ticket and release notes remain as long as there aren't any concerns.

https://github.com/django/django/pull/6791
Reply all
Reply to author
Forward
0 new messages