首页 > 解决方案 > Pytest:只运行 linter 检查(pytest-flake8),不运行测试

问题描述

我正在使用pytest-flake8插件来检查我的 Python 代码。每次我像这样运行棉绒:

pytest --flake8

除了 linting 之外,还运行所有测试。但我只想运行 linter 检查。

如何配置 pytest 使其仅对代码进行 lints 但跳过我的所有测试,最好通过命令行(或 conftest.py) -而不必在我的测试中添加跳过标记

标签: pythonpytest

解决方案


如果您的所有测试都在一个目录中,那么Pytests--ignore <<path>>选项在这里也很有效。

我通常将其隐藏在 make 命令后面。在这种情况下, myMakefiletestsdirectory 都位于存储库的根目录中。

.PHONY: lint

lint:
    pytest --flake8 --ignore tests

推荐阅读