Ticket #28212: allow_assigning_port.patch

File allow_assigning_port.patch, 2.2 KB (added by Robert Rollins, 7 years ago)
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    index 8203a38..894025a 100644
    a b class LiveServerThread(threading.Thread):  
    12571257    Thread for running a live http server while the tests are running.
    12581258    """
    12591259
    1260     def __init__(self, host, static_handler, connections_override=None):
     1260    def __init__(self, host, port, static_handler, connections_override=None):
    12611261        self.host = host
    1262         self.port = None
     1262        self.port = port
    12631263        self.is_ready = threading.Event()
    12641264        self.error = None
    12651265        self.static_handler = static_handler
    class LiveServerThread(threading.Thread):  
    12791279        try:
    12801280            # Create the handler for serving static and media files
    12811281            handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))
    1282             self.httpd = self._create_server(0)
    1283             self.port = self.httpd.server_address[1]
     1282            self.httpd = self._create_server()
     1283            if self.port == 0:
     1284                self.port = self.httpd.server_address[1]
    12841285            self.httpd.set_app(handler)
    12851286            self.is_ready.set()
    12861287            self.httpd.serve_forever()
    class LiveServerThread(threading.Thread):  
    12901291        finally:
    12911292            connections.close_all()
    12921293
    1293     def _create_server(self, port):
    1294         return WSGIServer((self.host, port), QuietWSGIRequestHandler, allow_reuse_address=False)
     1294    def _create_server(self):
     1295        return WSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False)
    12951296
    12961297    def terminate(self):
    12971298        if hasattr(self, 'httpd'):
    class LiveServerTestCase(TransactionTestCase):  
    13131314    other thread can see the changes.
    13141315    """
    13151316    host = 'localhost'
     1317    port = 0
    13161318    server_thread_class = LiveServerThread
    13171319    static_handler = _StaticFilesHandler
    13181320
    class LiveServerTestCase(TransactionTestCase):  
    13521354    def _create_server_thread(cls, connections_override):
    13531355        return cls.server_thread_class(
    13541356            cls.host,
     1357            cls.port,
    13551358            cls.static_handler,
    13561359            connections_override=connections_override,
    13571360        )
Back to Top