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
To reproduce this bug, you can use the following code:
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 the test we get:
FAILED test.py::test_homepage - ValueError: Pipe transport is only for pipes, sockets and character devices
If using pytest with -s switch, this bug does not appear. Therefore it is an incompatibility between pytest stdout capturing and the way aiologger is sending logs to stdout. I’m not sure, which side should handle this problem, therefore I post the issue on both projects.
The text was updated successfully, but these errors were encountered:
aiologger unconditionally creates stream/default handlers and has no own pytest integration taking care of redirection, object replacement or closing
thus it ends up with the stdio redirection breaking the objects it fetched
this is the reason why the general logging suggestion for any lib/application is to set up logging handlers at a managed place in application start-up instead of randomly at a module global logger creation
i consider that a bug solely in aiologger, as far as i can tell its suggested standard usage is a anti-pattern
My output of pip freeze is:
To reproduce this bug, you can use the following code:
After running the test we get:
If using pytest with
-s
switch, this bug does not appear. Therefore it is an incompatibility between pytest stdout capturing and the way aiologger is sending logs to stdout. I’m not sure, which side should handle this problem, therefore I post the issue on both projects.The text was updated successfully, but these errors were encountered: