DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documenta

运行unittest报错

Testing started at 20:31 ...
D:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pycharm\utrunner.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp

原因

imp 从 Python 3.4 之后弃用了,建议使用 importlib 代替

解决

1,在第一行,注释掉 imp,导入 importlib

2,注释 imp.load_source,使用 importlib.machinery.SourceFileLoader 加载模块

#module = imp.load_source(moduleName, fileName)
module = importlib.machinery.SourceFileLoader(moduleName, fileName).load_module()

打开 //JetBrains\PyCharm 2016.3\helpers\pycharm\utrunner.py 文件,做如下两步修改:

DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documenta_第1张图片

你可能感兴趣的:(python)