I have a fairly large dataset that I would like to use for testing a FastAPI endpoint. The issue I am having is that tests take a really long time to run. I am not sure if I have parameterized my tests correctly or if I have async setup correctly.
# Note: Func names, paths and other information is obfuscated
import pandas as pd
import pytest_asyncio
import pytest
from httpx import AsyncClient
from MODULE import app #FastAPI
dataset = pd.read_csv("data.csv")
@pytest_asyncio.fixture()
async def async_app_client():
async with AsyncClient(app=app, base_url='http://localhost') as client:
yield client
@pytest.mark.asyncio
@pytest.mark.parametrize("term", dataset['value'])
async def test_on_term(async_app_client, term):
response = await async_app_client.get(f"/endpoint?text={term}")
assert response.status_code == 200, f"{term} returned non 200 status"
Does this setup look correct? Tests run using this setup but the execution time for all the tests is abnormally long. Any other ideas to speed this up would be appreciated!
I've tried using pytest-xdist
but due to the nature of the data, sometimes there are repeated values and inconsistencies between results for a given test.