I have a flask app like this
from flask import Flask
import logging
app = Flask(__name__)
@app.route('/')
def catch_all():
logging.warning("I'm a warning")
return "This is a REST API"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
When I run it, I see the WARNING in the logs
WARNING:root:I'm a warning
I then create a test, like this
import fulfillment
def test_index():
fulfillment.app.testing = True
client = fulfillment.app.test_client()
r = client.get('/')
assert r.status_code == 200
assert 'This is a REST API' in r.data.decode('utf-8')
When I run the test using pytest
, I can't see the log message from my function under test. I found How can I see normal print output created during pytest run?, which sounds similar, but the pytest -s
option doesn't work and I think it's actually talking about output from the test function, not the function under test.
How can I see the logs from the function under test?