2015-05-25 65 views
1

我有一套的Python 3單元測試中,當被使用此命令行執行:我怎樣才能找出哪一行Python代碼產生PendingDeprecationWarning?

python3 -m unittest discover -f -v 

...正在生成PendingDeprecationWarning

/usr/local/Cellar/python3/3.4.2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py:32: 
    PendingDeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses 

有沒有一種簡單的方法我跟蹤哪個代碼最終使用imp.py,也許通過打開某種形式的堆棧跟蹤?我已經縮小了一點;它似乎只在我使用freezegun時觸發。然而,freezegun本身似乎並沒有使用imp

回答

4

當在命令行上調用蟒,傳遞選項-Werror到它。這會將所有警告轉化爲錯誤,並且當警告/錯誤未得到處理時,它將顯示一個回溯,該回溯將爲您提供行號和源文件,用於每個步驟以發出警告/錯誤。

+1

完美!這幫助我確定它是依賴的圖書館「六」。 –

+0

FWIW,這是錯誤:https://bitbucket.org/gutworth/six/issue/112/sixmovesreload_module-uses-deprecated-imp –