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.
* Attachment "allow_assigning_port.patch" added.
* 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>
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>
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>
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>
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>
* Attachment "allow_assigning_port-with-test.patch" added.
* 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>
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>
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>
* 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>
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>