diff --git a/veilid-python/tests/__init__.py b/veilid-python/tests/__init__.py index 6cabbd26..e69de29b 100644 --- a/veilid-python/tests/__init__.py +++ b/veilid-python/tests/__init__.py @@ -1,37 +0,0 @@ -import os -from functools import cache -from typing import AsyncGenerator - -import pytest_asyncio -import veilid -from veilid.json_api import _JsonVeilidAPI - -pytest_plugins = ("pytest_asyncio",) - - -@cache -def server_info() -> tuple[str, int]: - """Return the hostname and port of the test server.""" - VEILID_SERVER = os.getenv("VEILID_SERVER") - if VEILID_SERVER is None: - return "localhost", 5959 - - hostname, *rest = VEILID_SERVER.split(":") - if rest: - return hostname, int(rest[0]) - return hostname, 5959 - - -async def simple_update_callback(update: veilid.VeilidUpdate): - print(f"VeilidUpdate: {update}") - - -@pytest_asyncio.fixture -async def api_connection() -> AsyncGenerator[_JsonVeilidAPI, None]: - hostname, port = server_info() - api = await veilid.json_api_connect(hostname, port, simple_update_callback) - async with api: - # purge routes to ensure we start fresh - await api.debug("purge routes") - - yield api diff --git a/veilid-python/tests/conftest.py b/veilid-python/tests/conftest.py new file mode 100644 index 00000000..6cabbd26 --- /dev/null +++ b/veilid-python/tests/conftest.py @@ -0,0 +1,37 @@ +import os +from functools import cache +from typing import AsyncGenerator + +import pytest_asyncio +import veilid +from veilid.json_api import _JsonVeilidAPI + +pytest_plugins = ("pytest_asyncio",) + + +@cache +def server_info() -> tuple[str, int]: + """Return the hostname and port of the test server.""" + VEILID_SERVER = os.getenv("VEILID_SERVER") + if VEILID_SERVER is None: + return "localhost", 5959 + + hostname, *rest = VEILID_SERVER.split(":") + if rest: + return hostname, int(rest[0]) + return hostname, 5959 + + +async def simple_update_callback(update: veilid.VeilidUpdate): + print(f"VeilidUpdate: {update}") + + +@pytest_asyncio.fixture +async def api_connection() -> AsyncGenerator[_JsonVeilidAPI, None]: + hostname, port = server_info() + api = await veilid.json_api_connect(hostname, port, simple_update_callback) + async with api: + # purge routes to ensure we start fresh + await api.debug("purge routes") + + yield api diff --git a/veilid-python/tests/test_basic.py b/veilid-python/tests/test_basic.py index 20e07466..003ed054 100644 --- a/veilid-python/tests/test_basic.py +++ b/veilid-python/tests/test_basic.py @@ -5,9 +5,7 @@ import socket import pytest import veilid -from . import api_connection, simple_update_callback - -################################################################## +from .conftest import simple_update_callback @pytest.mark.asyncio diff --git a/veilid-python/tests/test_crypto.py b/veilid-python/tests/test_crypto.py index 81b04d1c..41712e7a 100644 --- a/veilid-python/tests/test_crypto.py +++ b/veilid-python/tests/test_crypto.py @@ -4,10 +4,6 @@ import pytest import veilid from veilid.api import CryptoSystem -from . import api_connection - -################################################################## - @pytest.mark.asyncio async def test_best_crypto_system(api_connection): diff --git a/veilid-python/tests/test_routing_context.py b/veilid-python/tests/test_routing_context.py index 4ab5f26f..eb730b80 100644 --- a/veilid-python/tests/test_routing_context.py +++ b/veilid-python/tests/test_routing_context.py @@ -1,12 +1,11 @@ # Routing context veilid tests import asyncio -import json import pytest import veilid -from . import api_connection, server_info +from .conftest import server_info ##################################################################