pytest如何管理log

2022-10-08 20:15:25 字數 1359 閱讀 4259

控制台命令執行修改格式:

--log-date-format="%y-%m-%d %h:%m:%s"
pytest.ini檔案下新增以下**,修改log輸出:

[pytest]

log_format = %(asctime)s %(levelname)s %(message)s

log_date_format = %y-%m-%d %h:%m:%s

3.臨時修改日誌等級caplog fixture

def test_foo(caplog):

caplog.set_level(logging.info)

pass

直到test_foo結束後再恢復到之前的設定;

4.capture.clear()清除自定義日誌:

def test_something_with_clearing_records(caplog):

some_method_that_creates_log_records()

caplog.clear()

your_test_method()

assert ["foo"] == [rec.message for rec in caplog.records]

清除捕獲的記錄和格式化的日誌輸出字串

5.the full api is **ailable atpytest.logcapturefixture:: pytest.logcapturefixture

capturelog缺少向後相容,如果是還是要使用,按麼在pytest.ini中新增如下**:

addopts=-p no:logging
tips:

392/5000 

日誌級別不再改變,除非log_level配置或——log -level命令列選項明確要求。這允許使用者自己配置記錄器物件。設定log_level將設定全域性捕獲的級別,因此,如果某個特定測試需要的級別低於此級別,請使用caplog.set_level()功能,否則該測試將容易失敗。

live logs現在預設是禁用的,可以將log_cli配置選項設定為true啟用。啟用後,詳細程度會增加,因此每個測試的日誌記錄都是可見的。仍然在pytest.ini配置檔案中新增

如果希望部分恢復3.3版的日誌記錄行為,可以將此選項新增到ini檔案中:

[pytest]

log_cli=true

log_level=notset

如何輸出xapian debug的log

xapian內部關係呼叫比較複雜,想要了解內部的函式呼叫關係比較有難度,好在內部使用logcall ctor等輸出了很多log,如何列印這些log呢?命令如下 cd xapian core 1.4.5 xapin source downloaded install mkdir build cd bu...

日誌管理 log4js

版本 安裝 npm install log4js封裝 log4js 在專案根目錄下新建檔案logger.js var log4js require log4js log4js.configure replaceconsole true 替換 console.log levels exports.lo...

展訊平台如何除錯之打LOG 串列埠log

公司最近做一款資料卡,還是用的展訊的8800,板子還沒回來,想先在8802上實驗一下 但是在移植到8802上的時候板子一直都跑不起來。以前出現問題的時候第一反映就是去打log,查異常,但是這次貌似死得很早,根本就認不出diag!怎麼辦呢?在這種情況下就用串列埠來列印吧,選擇的理由是串列埠初始化簡單,...