我怎样才能找出生成PendingDeprecationWarning的Python代码行?

时间:2015-05-25 15:42:45

标签: python-3.x deprecated freezegun

我有一组Python 3单元测试,当使用此命令行执行时:

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

1 个答案:

答案 0 :(得分:4)

在命令行上调用python时,将选项-Werror传递给它。这会将所有警告转换为错误,并且当未处理警告/错误时,它将显示一个回溯,该回溯将为每个允许警告/错误的步骤提供行号和源文件。