start with test_api (async, using fastapi)

This commit is contained in:
Helmut Merz 2026-09-14 18:15:41 +02:00
parent 7b9b3e2d47
commit 37d7a31650
3 changed files with 34 additions and 6 deletions

View file

@ -32,13 +32,14 @@ app = [
auth = ["pyjwt[crypto]", "cryptography", "requests"]
api = ["fastapi[standard]"]
test = ["zope.testrunner"]
#test = ["pytest"]
apitest = ["pytest", "httpx2"]
[tool.setuptools]
packages = ["scopes"]
#[tool.pytest.ini_options]
#addopts = "-vv"
#python_files = "test_standard.py" # default: run only `standard` tests
[tool.pytest.ini_options]
addopts = ["-s"]
#test_paths = ["tests"]
python_files = ["test_api.py"]
# use .pytest.ini file with `python_files = test_*.py` to run all tests

View file

@ -5,10 +5,10 @@ from fastapi import FastAPI
app = FastAPI()
@app.get('/')
def read_root():
async def read_root():
return {'Hello': 'World'}
@app.get('/persons/{name}')
def read_person(name: str, q: str | None = None):
async def read_person(name: str, q: str | None = None):
return {'name': name, 'query': q}

27
scopes/tests/test_api.py Normal file
View file

@ -0,0 +1,27 @@
# scopes.tests.test_api
"""Tests for the fastapi- (and asyncio-) based stuff."""
import sys
print('***', sys.path)
import pytest
from fastapi.testclient import TestClient
from httpx2 import ASGITransport, AsyncClient
from scopes.api.main import app
def async_client():
return AsyncClient(transport=ASGITransport(app=app), base_url='http://test')
#@pytest.mark.anyio
#async def test_root():
#async with async_client() as clt:
#response = await clt.get('/')
def test_root():
with TestClient(app) as clt:
response = clt.get('/')
assert response.status_code == 200
assert response.json() == {'Hello': 'World'}