From a86ac17fd619d2d07a678d3c1fe9a3009713bd7e Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sat, 12 Dec 2020 15:45:03 -0500 Subject: [PATCH] added test fixture --- services/api/app/main.py | 2 +- services/api/tests/conftest.py | 10 ++++++++++ services/api/tests/test_main.py | 10 ++-------- 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 services/api/tests/conftest.py diff --git a/services/api/app/main.py b/services/api/app/main.py index e38afc3..93407c7 100644 --- a/services/api/app/main.py +++ b/services/api/app/main.py @@ -5,6 +5,6 @@ app = FastAPI() @app.get('/ping') -def pong(): +async def pong(): now = dt.datetime.now(dt.timezone.utc) return {'ping': "pong!", 'now': now} diff --git a/services/api/tests/conftest.py b/services/api/tests/conftest.py new file mode 100644 index 0000000..3d9516b --- /dev/null +++ b/services/api/tests/conftest.py @@ -0,0 +1,10 @@ +import pytest +from starlette.testclient import TestClient + +from app.main import app + + +@pytest.fixture(scope="module") +def test_app(): + client = TestClient(app) + yield client diff --git a/services/api/tests/test_main.py b/services/api/tests/test_main.py index a2f6c5a..6a23e17 100644 --- a/services/api/tests/test_main.py +++ b/services/api/tests/test_main.py @@ -1,11 +1,5 @@ -from app.main import app -from starlette.testclient import TestClient - -client = TestClient(app) - - -def test_read_main(): - response = client.get('/ping') +def test_read_main(test_app): + response = test_app.get('/ping') assert response.status_code == 200 data = response.json() assert "pong" in data['ping']