conftest.py 987 B

1234567891011121314151617181920212223242526272829303132
  1. import pytest
  2. import pytest_asyncio
  3. from huggingface_hub import snapshot_download
  4. from tests.utils import RemoteOpenAIServer
  5. from .utils import ARGS, CONFIGS, ServerConfig
  6. # for each server config, download the model and return the config
  7. @pytest.fixture(scope="session", params=CONFIGS.keys())
  8. def server_config(request):
  9. config = CONFIGS[request.param]
  10. # download model and tokenizer using transformers
  11. snapshot_download(config["model"])
  12. yield CONFIGS[request.param]
  13. # run this for each server config
  14. @pytest.fixture(scope="session")
  15. def server(request, server_config: ServerConfig):
  16. model = server_config["model"]
  17. args_for_model = server_config["arguments"]
  18. with RemoteOpenAIServer(model, ARGS + args_for_model,
  19. max_wait_seconds=480) as server:
  20. yield server
  21. @pytest_asyncio.fixture
  22. async def client(server: RemoteOpenAIServer):
  23. async with server.get_async_client() as async_client:
  24. yield async_client