con*_* yu 1 debugging logging pytest
''' func.py '''
import logging
def func():
''' func '''
logging.basicConfig(
format="\t %(filename)s"
" %(funcName)s"
"-ln%(lineno)d"
" %(levelname)s \n%(message)s",
level=logging.DEBUG,
# stream=sys.stdout,
)
logger = logging.getLogger()
logger.info(" >>> logger func info")
logger.warning(" >>> logger func warning")
print(" >>> print func info")
def test_func():
''' test func '''
# caplog.set_level(logging.DEBUG)
func()
if __name__ == "__main__":
test_func()
Run Code Online (Sandbox Code Playgroud)
假设我将上面的代码另存为func.py。当我跑步
pytest -s func.py
Run Code Online (Sandbox Code Playgroud)
我得到
" >>> print func info".
Run Code Online (Sandbox Code Playgroud)
我如何获得
" >>> logger func info"
Run Code Online (Sandbox Code Playgroud)
和
“ >>>记录器功能警告”
当我跑步时
pytest -s func.py
Run Code Online (Sandbox Code Playgroud)
我希望能够这样做的原因如下。我通常在我的代码中插入logging.debug / info等。有时,当我运行pytest时,我想查看logging.debug / info发出的消息。我在网上搜索了很长时间,但找不到方法。在此先感谢您的帮助。
方式-在pytest.ini中添加:
[pytest]
log_cli = true
Run Code Online (Sandbox Code Playgroud)
然后运行pytest
pytest --log-cli-level=10 func.py
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2088 次 |
| 最近记录: |