When my methods in a View
class are executed by pytest
, the logging statements don't produce any outputs on the console. Is that expected behavior or am I missing something?
This is the view:
import logging
from django.views import View
logger = logging.getLogger(__name__)
class FancyWebhook(View):
def post(self, request, *args, **kwargs):
logger.info("DUMMY logging")
print("DUMMY printing")
return HttpResponse(status=200)
The logging configuration in configs/settings/test.py
:
# ...
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {"class": "logging.StreamHandler"},
},
"loggers": {
"django": {
"handlers": ["console"],
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
},
},
}
The test method:
import pytest
@pytest.mark.django_db
def test_fancy_webook_empty_payload_fails(client):
print("calling client.post()...")
response = client.post('/pricing/fancywebhook', {}, content_type='application/json')
assert response.status_code == 403
Running the test via pytest --ds=config.settings.test
only prints the error that assert 301 == 403
to the console, but neither the "DUMMY logging" nor the "DUMMY printing" statements.
I'm surely missing the obvious, am I not?