我有一个这样的烧瓶应用程序
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)
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我在日志中看到警告
WARNING:root:I'm a warning
Run Code Online (Sandbox Code Playgroud)
然后我创建一个测试,就像这样
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')
Run Code Online (Sandbox Code Playgroud)
当我使用 运行测试时pytest,我看不到测试中函数的日志消息。我发现如何查看在 pytest 运行期间创建的正常打印输出?,听起来很相似,但该pytest -s选项不起作用,我认为它实际上是在谈论测试函数的输出,而不是被测函数。
如何查看被测函数的日志?