make NominatimAPI[Async] a context manager

If close() isn't properly called, it can lead to odd error messages
about uncaught exceptions.
This commit is contained in:
Sarah Hoffmann
2024-08-19 11:31:38 +02:00
parent 8b41b80bff
commit c2594aca40
8 changed files with 53 additions and 65 deletions

View File

@@ -9,6 +9,7 @@ Helper fixtures for API call tests.
"""
from pathlib import Path
import pytest
import pytest_asyncio
import time
import datetime as dt
@@ -244,3 +245,9 @@ def frontend(request, event_loop, tmp_path):
for api in testapis:
api.close()
@pytest_asyncio.fixture
async def api(temp_db):
async with napi.NominatimAPIAsync(Path('/invalid')) as api:
yield api