python - 以编程方式调用 Pylint

标签 python automated-tests pylint

我想调用 Pylint 检查器,仅限于错误信号部分,作为我的单元测试的一部分。所以我检查了 Pylint 可执行脚本,找到了 pylint.lint.Run 辅助类,我迷失在一个很长的 __init__ 函数中,最后调用了 sys.exit().

有人尝试过并设法做到这一点吗?

梦想计划是这样的:

if __name__ == '__main__':
  import pylint.lint
  pylint.lint.something(__file__, justerrors=True)
  # now continue with unit testing

有什么提示吗?除了“复制 __init__ 方法并跳过 sys.exit()”之外,我的意思是?

我不需要由 Pylint 运行的测试,它也可能是 pyflakes 或其他软件:请随意提出替代方案。

最佳答案

查看 pylint/epylint.py 文件,其中包含两种以编程方式启动 Pylint 的不同方法。

你也可以直接调用

from pylint.lint import Run
Run(['--errors-only', 'myfile.py'])

例如。

关于python - 以编程方式调用 Pylint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2028268/

相关文章:

python - 在 __init__ 中使用继承的类方法

python - 为什么 math.sqrt 会导致 ValueError : math domain error?

testing - 自动规划自动回归测试执行顺序的框架?

pylint - pylint 和 git.exc 的奇怪错误

python - 在 sklearn 中持久化数据

testing - 如何从一个文件位置获取数据并使用 tcl 代码运行

Android Studio 在运行测试时不允许一次进行多个部署

python - 在 pylint 和 mypy 中处理 Python 类重新定义警告

python - 避免 Pylint 警告 E1101 : 'Instance of .. has no .. member' for class with dynamic attributes

Python Selenium 通过 Windows 上传上传文件