Pytest:只运行linter检查(pytestflake8),不运行测试

2024-06-09 20:53:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用pytest-flake8插件来lint我的Python代码。 每次我都是这样运行的:

pytest --flake8

除了linting之外,还运行所有测试。 但我只想检查一下皮棉。在

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


Tags: 代码命令行py标记插件flake8pytestlint
2条回答

您可以自己更改测试运行逻辑,例如,当 flake8arg通过时忽略收集的测试:

# conftest.py

def pytest_collection_modifyitems(session, config, items):
    if config.getoption(' flake8'):
        items[:] = [item for item in items if item.get_marker('flake8')]

现在只执行flake8测试,其余的将被忽略。在

我也遇到了同样的问题,经过一番挖掘,我意识到我只想运行flake8

flake8 <path to folder>

就这样。不需要运行其他任何东西,因为您的flake8configuration独立于PyTest。在

相关问题 更多 >