[英]Skipping import modules in pytest from the command line
The documentation for pytest
suggests you can skip certain imports: pytest
的文档建议您可以跳过某些导入:
https://docs.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency https://docs.pytest.org/en/latest/skipping.html#skiping-on-a-missing-import-dependency
We are trying to run pylint under pytest and in some cases importing tensorflow
causes issues because of system dependencies.我们正在尝试在 pytest 下运行 pylint,在某些情况下,由于系统依赖性,导入
tensorflow
会导致问题。 The documentation shows a way of skipping the import in code, is it possible to skip imports like this from the command line of pytest
?文档显示了一种在代码中跳过导入的方法,是否可以从
pytest
的命令行跳过这样的pytest
?
There is no such feature in pytest
, so you should do this directly in code (usually in a conftest.py
). pytest
没有这样的功能,因此您应该直接在代码中执行此操作(通常在conftest.py
)。
A hacky workaround to do the same directly at the command line woud be:直接在命令行执行相同操作的hacky解决方法是:
python -c "import pytest; pytest.importorskip('tensorflow'); pytest.main()"
Better would be to use one of the existing hooks to add your own command-line option to pytest, so it can be specified clearly like --no-tensorflow
or whatever.更好的是使用现有的钩子之一将您自己的命令行选项添加到 pytest,因此可以像
--no-tensorflow
或其他什么一样清楚地指定它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.