限制 py.test 只运行 pylint 而不是 unittests [英] Restricting py.test to only run pylint and not unittests

查看:66
本文介绍了限制 py.test 只运行 pylint 而不是 unittests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行 py.test 并只执行 pylint,而不是 unittests.

此页面上的文档表明您可以做到:

https://pypi.org/project/pytest-pylint/<块引用>

您可以通过键入以下内容将测试运行限制为仅执行 pylint 检查而不执行任何其他测试:

 py.test --pylint -m pylint

但是当我完全运行该命令时,我仍然从 py.test 发现的单元测试中得到错误.linting 过程似乎按预期运行,然后我在报告的 unittest 文件中收到一堆错误.这似乎与文档相反.

py.test --version 显示我正在使用 0.14.0:

$ py.test --version这是 pytest 4.0.0 版,从/usr/local/lib/python3.6/dist-packages/pytest.py 导入setuptools 注册的插件:pytest-pylint-0.14.0 在/usr/local/lib/python3.6/dist-packages/pytest_pylint.py

解决方案

代答:

<块引用>

您是否在单元测试或实际中遇到关于代码风格的 linter 错误单元测试失败?– 格迪米纳斯 2 月 7 日 20:12

好问题,主要是模块导入错误,pythonpath 问题unittest 文件,虽然很容易解决,但不应该在全部.我们只希望 Jenkins 的这一部分出现 lint 错误管道.我们将定义管道的另一部分来运行单元测试适当地.– 大卫帕克斯 2 月 7 日 20:14

">主要是模块导入错误,单元测试文件中的 pythonpath 问题,虽然很容易解决,但根本不应该运行. - 我认为这里的解释是 pytest 正在尝试加载单元测试模块,但实际上不会运行它们.-m pylint 是一个标记过滤器,这意味着只有标记为pylint"的测试才会被过滤.将不得不运行.因此 pytest 必须查看所有测试并检查它们的标记.我猜想解决 import/pythonpath 问题会解决这个问题,并且 py.test --pylint -m pylint 会按预期运行.– 格迪米纳斯 2 月 7 日 20:47

I'm trying to run py.test and execute only pylint, but not unittests.

The documentation on this page indicates you can do it:

https://pypi.org/project/pytest-pylint/

You can restrict your test run to only perform pylint checks and not any other tests by typing:

  py.test --pylint -m pylint

But when I run that command exactly I still get errors from unittests that py.test found. The linting process seems to run as expected, then I get a bunch of errors in unittest files reported. This seems contrary to the documentation.

py.test --version shows that I'm using 0.14.0:

$ py.test --version
This is pytest version 4.0.0, imported from /usr/local/lib/python3.6/dist-packages/pytest.py
setuptools registered plugins:
  pytest-pylint-0.14.0 at /usr/local/lib/python3.6/dist-packages/pytest_pylint.py

解决方案

Answering on behalf of comments:

Are you getting linter errors about code style in unit tests or actual unit tests failures? – Gediminas Feb 7 at 20:12

Good question, mostly module import errors, pythonpath issues in the unittest files that, while easy to solve, aren't supposed to be run at all. We want the lint errors only in this part of the Jenkins pipeline. We will define another part of the pipeline to run unittests properly. – David Parks Feb 7 at 20:14

"> mostly module import errors, pythonpath issues in the unittest files that, while easy to solve, aren't supposed to be run at all." - I think the explanation here is that pytest is trying to load unit test modules, but won't actually run them. -m pylint is a mark filter which means that only tests marked as "pylint" will have to be run. So pytest has to look through all the tests and inspect their marks. I would guess that solving the import/pythonpath issues would address the problem and py.test --pylint -m pylint would behave as expected. – Gediminas Feb 7 at 20:47

这篇关于限制 py.test 只运行 pylint 而不是 unittests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆