added test fixture

master
Drew Bednar 4 years ago
parent 9db3510495
commit a86ac17fd6

@ -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}

@ -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

@ -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']

Loading…
Cancel
Save