def run_server(port, cert_file_name):
    """Utility method to create a mock server that serves a specific certificate"""

    def start_server():
        server = HTTPServer(('localhost', port), SimpleHTTPRequestHandler)
        server.socket = ssl.wrap_socket(server.socket,
                                        server_side=True,
                                        certfile=cert_file_name,
                                        ssl_version=ssl.PROTOCOL_TLSv1_2)
        server.serve_forever()
        print(f"Started https server on port {port} using cert file {cert_file_name}")

    daemon = threading.Thread(name=f'server_{cert_file_name}', target=start_server)
    daemon.daemon = True  # Set as a daemon so it will be killed once the main thread is dead.
    daemon.start()
    return daemon
Utility method to create a mock server that serves a specific certificate
lemur/tests/test_certificates.py