Beispiel #1
0
def sync_server_from_arguments(request):
    """
    Starts the sync HTTP server for a given set of parameters passed as arguments, with server on a separate thread

    Yields:
    * the server (useful to interrogate for the server address)
    * environment variables (useful to interrogate for correct responses)
    """
    environ = {k.lower(): v for k, v in request.param.items()}
    settings = environ
    server = server_factory(**settings)
    server_thread = threading.Thread(target=server.serve_forever)
    # Put on daemon so it doesn't keep pytest from ending
    server_thread.daemon = True
    server_thread.start()
    yield server, environ
Beispiel #2
0
def sync_server(request):
    """
    Starts the sync HTTP server for a given set of environment variables on a separate thread

    Yields:
    * the server (useful to interrogate for the server address)
    * environment variables (useful to interrogate for correct responses)
    """
    environ = request.param
    with mock.patch.dict(os.environ, environ):
        # Create a server at an available port and serve it on a thread as a daemon
        # This will result in a collection of servers being active - not a great way
        # if this fixture is run many times during a test, but ok for now
        settings = get_settings_from_env()
        server = server_factory(**settings)
        server_thread = threading.Thread(target=server.serve_forever)
        # Put on daemon so it doesn't keep pytest from ending
        server_thread.daemon = True
        server_thread.start()
        yield server, environ