You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import sys
import pytest
from fastapi import FastAPI, APIRouter
from httpx import AsyncClient
from starlette.requests import Request
from aiologger.logger import Logger
logger = Logger.with_default_handlers(name='my-logger')
app = FastAPI()
router = APIRouter()
@router.get('/')
async def homepage(request: Request):
await logger.info('Rendering the homepage')
return {"message": "Hello World"}
app.include_router(router)
@pytest.mark.asyncio
async def test_homepage():
async with AsyncClient(app=app, base_url='http://my-page/') as client:
response = await client.get('/')
assert response.json()['message'] == 'Hello World'
After running pytest we get:
FAILED test.py::test_homepage - ValueError: Pipe transport is only for pipes, sockets and character devices
Note that if running pytest with the -s switch, the test passes. The issue is therefore with the pytest stdout capturing being incompatible with aiologger’s stream handler.
Because I’m not 100% sure, which side should really handle the issue, I will post the same ticket on both pytest and aiologger page.
The text was updated successfully, but these errors were encountered:
from the pytest-dev/pytest#9119 i take the stance that aiologgewr is reponsible and uses a logging setup antipattern (which is to set up handlers at module/library level instead of the application startup
To reproduce this bug, use the following code:
After running pytest we get:
Note that if running pytest with the
-s
switch, the test passes. The issue is therefore with the pytest stdout capturing being incompatible with aiologger’s stream handler.Because I’m not 100% sure, which side should really handle the issue, I will post the same ticket on both pytest and aiologger page.
The text was updated successfully, but these errors were encountered: