[Django] #28212: The port 0 change for LiveServerTestCase breaks Selenium testing in Docker

39 views
Skip to first unread message

Django

unread,
May 16, 2017, 4:30:29 PM5/16/17
to django-...@googlegroups.com
#28212: The port 0 change for LiveServerTestCase breaks Selenium testing in Docker
---------------------------------------------+------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
As of Django 1.11, I cannot see any way for selenium tests to work in a
Docker environment. Binding `LiveServerTestCase`'s `WSGIServer` to port 0
makes it impossible for your host image's Dockerfile to expose the
necessary port for a Selenium server to be able to connect to your host.

I'd like to propose the attached patch to remedy this problem. It leaves
the default behavior the same as it currently stands, but allows the
developer to override that behavior as needed by simply defining the
`port` property in their test class.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 16, 2017, 4:30:44 PM5/16/17
to django-...@googlegroups.com
#28212: The port 0 change for LiveServerTestCase breaks Selenium testing in Docker
-----------------------------------+--------------------------------------

Reporter: Robert Rollins | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Robert Rollins):

* Attachment "allow_assigning_port.patch" added.

Django

unread,
May 17, 2017, 9:42:45 AM5/17/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------

Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization


Comment:

I think it would be nice to have a test for that, perhaps with some
mocking. The 1.11 release notes could also be amended to mention this,
with a note that it's added in 1.11.2.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:1>

Django

unread,
May 17, 2017, 8:32:49 PM5/17/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Robert Rollins):

Hmm, never written a test for django before. How should I go about that?

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:2>

Django

unread,
May 17, 2017, 9:42:43 PM5/17/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham):

The contributing docs for
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/unit-tests/ unit tests] should help.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:3>

Django

unread,
May 17, 2017, 9:51:43 PM5/17/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Simon Charette):

> Hmm, never written a test for django before. How should I go about that?

I suggest you add a test method to
[https://github.com/django/django/blob/650bf6714d5648811a8bc08ce53b7fa86cc38d40/tests/servers/tests.py#L122
tests.servers.tests. LiveServerPort] which finds an available port, set it
as an attribute to dynamically a create `LiveServerBase` subclass (look at
`test_port_bind` for that), call `setUpClass()` on it and assert
`TestClass.live_server_url` contains the specified port.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:4>

Django

unread,
May 19, 2017, 5:19:55 PM5/19/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Robert Rollins):

Well that was much less painful than I expected! I've had some pretty
harrowing experiences trying to set up and run other app's test suites in
the past, but Django's was a breeze!

Here's a new patch with the code change and a test I wrote. Unfortunately,
I don't really know what to do about exceptions thrown during the test
(like what
`LiveServerPort.test_port_bind` does), so the test code isn't complete.
But I think it exercises the relevant code changes, at least.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:5>

Django

unread,
May 19, 2017, 5:20:06 PM5/19/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Robert Rollins):

* Attachment "allow_assigning_port-with-test.patch" added.

Django

unread,
May 20, 2017, 11:14:00 AM5/20/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* cc: Simon Charette (added)


Comment:

Awesome work Robert,

Glad to hear it was easy to get the test suite running on your machine!

Would it be possible for you to submit your patch as Github pull request?
It would allow the [https://djangoci.com/ CI infrastructure] to run the
full test suite against your patch and assert everything is fine. This
will also give the patch more visibility and make the review easier.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:6>

Django

unread,
May 22, 2017, 1:03:28 PM5/22/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Robert Rollins):

Sure thing! The reason I didn't do so initially was that I didn't know if
I should submit the PR against the stable/1.11.x branch, or against master
(which appears to be whole hog into Django 2.0 mode, so I'm not even sure
my change would apply cleanly). I'll try it as a commit against
stable/1.11.x, and see what happens.

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:7>

Django

unread,
May 22, 2017, 1:23:37 PM5/22/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Robert Rollins):

OK, I opened a PR for this patch @
https://github.com/django/django/pull/8534

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:8>

Django

unread,
May 30, 2017, 6:36:27 PM5/30/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"877d7b71ae952b3bc946e5187d6c23039a71614d" 877d7b7]:
{{{
#!CommitTicketReference repository=""
revision="877d7b71ae952b3bc946e5187d6c23039a71614d"
[1.11.x] Fixed #28212 -- Allowed customizing the port that
LiveServerTestCase uses.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:9>

Django

unread,
May 30, 2017, 6:49:37 PM5/30/17
to django-...@googlegroups.com
#28212: Allow customizing the port that LiveServerTestCase uses
--------------------------------------+------------------------------------
Reporter: Robert Rollins | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Testing framework | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"b6d4b6e5445323c4a8a423d34c2ec9a30864ce19" b6d4b6e]:
{{{
#!CommitTicketReference repository=""
revision="b6d4b6e5445323c4a8a423d34c2ec9a30864ce19"


Fixed #28212 -- Allowed customizing the port that LiveServerTestCase uses.

Forwardport of 877d7b71ae952b3bc946e5187d6c23039a71614d from stable/1.11.x
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28212#comment:10>

Reply all
Reply to author
Forward
0 new messages