gpt4 book ai didi

python - 从命令行跳过 pytest 中的导入模块

转载 作者:行者123 更新时间:2023-12-01 08:20:32 25 4
gpt4 key购买 nike

pytest 的文档建议您可以跳过某些导入:

https://docs.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency

我们尝试在 pytest 下运行 pylint,在某些情况下导入 tensorflow 会因系统依赖性而导致问题。文档展示了一种在代码中跳过导入的方法,是否可以从pytest的命令行跳过这样的导入?

最佳答案

pytest 中没有此类功能,因此您应该直接在代码中执行此操作(通常在 conftest.py 中)。

直接在命令行执行相同操作的一种巧妙的解决方法是:

python -c "import pytest; pytest.importorskip('tensorflow'); pytest.main()"

更好的是使用现有的 hooks 之一将您自己的命令行选项添加到 pytest,以便可以像 --no-tensorflow 或其他内容一样明确指定。

关于python - 从命令行跳过 pytest 中的导入模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54677638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com