pylintpytest如何抛出F6401 Canenumeratepytestfixtures

2024-06-25 23:37:51 发布

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

你能解释一下运行pylint时出现提示“F6401”的原因吗pylint-pytest plugin cannot enumerate and collect pytest fixtures. Please run `pytest --fixtures --collect-only path/to/current/module.py` and resolve any potential syntax error or package dependency issues (Can-enumerate-pytest-fixtures)

我想知道它是如何工作的,或者为什么会出现,有时会有不同的输出。相同的代码,有时两个,有时更多。我很沮丧

我确实在没有任何异常提示的情况下运行了pytest --fixtures --collect-only,并且测试正常

说明:

在我对现有代码进行微调后,包括运行pylintpytestisort,一切正常。我添加了一个包含三个模块的新包executor,一个是base.py的抽象模块,两个对应于不同的实现模块(local.pydocker.py

然后我运行isort,并且pylint工作正常

然后在模块的__init__.py文件中导入基类和两个实现类,并添加一个工厂方法

当我再次运行pylint时,输入告诉我一些测试模块与F6401有问题

再次强调,在我添加此模块之前,一切都很好。但是现在我刚刚添加了这个模块的源代码,这个异常将会出现

更让我困惑的是,提示我的模块没有包含任何装置。我再次运行了pylint,发现F6401有更多的测试模块(比上次多几倍)

我一直在为一个新项目使用PyLint来检查模块间的模式迁移,当我迁移到这个模块时,我无法继续

操作系统环境

  • python 3.7
  • 操作系统:Deepin(基本Debian)
  • IDE:Pycharm

软件包版本

  • pylint 3.0.0a3
  • pylint pytest 1.1.2
  • PY2.4.7
  • pytest 6.2.3
  • pytest asyncio 0.14.0
  • pytest cov 2.11.1
  • pytest模拟3.5.1

ISSUE about this question.


Tags: 模块and代码pyonlypytest原因plugin
1条回答
网友
1楼 · 发布于 2024-06-25 23:37:51

调试源代码后,我发现问题的原因是运行pytest从源代码收集装置时pylint-pytest中的错误,然后pylint-pytest将错误传递给PyLint

我的源代码有一个类型注释错误,该错误导致pytest从该模块中查找错误的fixture,并将该错误传递给pylint。但我不清楚为什么会有不同的输出

通过调试源代码,我们知道pylint-pytest向pylint注册自己,当pylint检查所有文件时,它将文件传递给pylint pytest的FixtureChecker

https://github.com/reverbc/pylint-pytest/blob/62676386f80989cc0373d77bc5dc74acc635fd7a/pylint_pytest/checkers/fixture.py#L92-L142

FixtureChecker中的visit_module方法将文件传递给pytest,运行pytest <module_file> fixtures collect-only,同时将FixtureCollector插件加载到pytest中

https://github.com/reverbc/pylint-pytest/blob/62676386f80989cc0373d77bc5dc74acc635fd7a/pylint_pytest/checkers/fixture.py#L125-L131

pytest_collectreport中,如果pytest报告了错误,则会记录该错误并将错误信息传递给pytest

https://github.com/reverbc/pylint-pytest/blob/62676386f80989cc0373d77bc5dc74acc635fd7a/pylint_pytest/checkers/fixture.py#L24-L34

我认为这种逻辑没有道理。Pytest应该只从测试模块收集fixture,而不是从所有模块收集fixture,Pylint Pytest应该在Pylint检查时过滤掉源代码

在这一点上,我的疑虑已经消失了。谢谢

相关问题 更多 >