veilid/veilid-python/tests/conftest.py

29 lines
665 B
Python
Raw Normal View History

"""Common test fixtures."""
2023-06-17 14:37:39 -04:00
from typing import AsyncGenerator
import pytest
2023-06-17 14:37:39 -04:00
import pytest_asyncio
import veilid
from veilid.json_api import _JsonVeilidAPI
2023-06-17 14:37:39 -04:00
pytest_plugins = ("pytest_asyncio",)
2023-06-17 14:37:39 -04:00
async def simple_update_callback(update: veilid.VeilidUpdate):
2024-10-18 21:28:25 -04:00
pass
2023-06-17 14:37:39 -04:00
@pytest_asyncio.fixture
async def api_connection() -> AsyncGenerator[_JsonVeilidAPI, None]:
try:
api = await veilid.api_connector(simple_update_callback)
except veilid.VeilidConnectionError:
pytest.skip("Unable to connect to veilid-server.")
2023-06-17 14:37:39 -04:00
async with api:
# purge routes to ensure we start fresh
await api.debug("purge routes")
yield api