import logging
logging.basicConfig(level=logging.DEBUG)
def test_demo():
logging.debug("This is a log!")
控制台输出:
Testing started at 17:28 ...
E:\pyDemo\seleniumDemo\venv\Scripts\python.exe "D:\pycharm\PyCharm 2018.3.5\helpers\pycharm_jb_pytest_runner.py" --path E:/pyDemo/seleniumDemo/test_log1.py
Launching pytest with arguments E:/pyDemo/seleniumDemo/test_log1.py in E:\pyDemo\seleniumDemo
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-6.0.0, py-1.9.0, pluggy-0.13.1
rootdir: E:\pyDemo\seleniumDemocollected 1 item
test_log1.py . [100%]
============================== 1 passed in 0.15s ==============================
Process finished with exit code 0