diff --git a/.coveragerc b/.coveragerc index a868b80..c7e13f0 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,7 @@ # .coveragerc to control coverage.py [run] branch = True +parallel = True omit = */site-packages/* */distutils/* @@ -16,7 +17,6 @@ omit = */src/* source = image_prediction - src relative_files = True data_file = .coverage diff --git a/test/integration_tests/server_test.py b/test/integration_tests/server_test.py index 8951940..b049bd1 100644 --- a/test/integration_tests/server_test.py +++ b/test/integration_tests/server_test.py @@ -1,5 +1,5 @@ +import socket from multiprocessing import Process -from time import sleep import pytest import requests @@ -12,14 +12,17 @@ def host(): return "127.0.0.1" -@pytest.fixture -def port(host): - import socket +def get_free_port(host): sock = socket.socket() sock.bind((host, 0)) return sock.getsockname()[1] +@pytest.fixture +def port(host): + return get_free_port(host) + + @pytest.fixture def url(host, port): return f"http://{host}:{port}" @@ -34,16 +37,20 @@ def predict_fn(): @pytest.fixture -def run_server_args(host, port, predict_fn): - prediction_server = make_prediction_server(predict_fn) - return {"app": prediction_server, "host": host, "port": port} +def server(predict_fn): + server = make_prediction_server(predict_fn) + return server @pytest.fixture -def server(run_server_args): +def host_and_port(host, port, server): + return {"host": host, "port": port} + +@pytest.fixture(autouse=True) +def server_process(server, host_and_port): def get_server_process(): - return Process(target=run_prediction_server, kwargs=run_server_args) + return Process(target=run_prediction_server, kwargs={"app": server, **host_and_port}) server = get_server_process() server.start() @@ -51,24 +58,19 @@ def server(run_server_args): server.terminate() -# def test_run_server(): -# prediction_server = make_prediction_server(predict_fn) -# return Process(target=run_prediction_server, kwargs={"app": prediction_server, "host": host, "port": port}) - - -def test_server_predict(server, url): +def test_server_predict(url): response = requests.post(url) response.raise_for_status() assert response.json() == 42 -def test_server_health_check(server, url): +def test_server_health_check(url): response = requests.get(f"{url}/health") response.raise_for_status() assert response.status_code == 200 -def test_server_ready_check(server, url): +def test_server_ready_check(url): response = requests.get(f"{url}/ready") response.raise_for_status() assert response.status_code == 200