gpt4 book ai didi

python - PyTest:跳过整个模块/文件(python 2 和 3)

转载 作者:太空狗 更新时间:2023-10-30 02:02:19 25 4
gpt4 key购买 nike

如果导入不起作用,我想跳过整个测试:

try:
import networkx
except:
import pytest
pytest.skip()

这适用于 python-2.7 和 python-3.5,两者都使用 pytest-2.8.1。当我尝试使用 pytest-3.0.5 在 python-3.6 中运行代码时,出现以下错误:

Using pytest.skip outside of a test is not allowed. If you are trying to decorate a test function, use the @pytest.mark.skip or @pytest.mark.skipif decorators instead.

如何编写适用于所有提到的环境的代码/测试?我已经尝试像这样重写 except block ,但它只适用于最新的配置:

try:
pytest.skip()
except:
pytestmark = pytest.mark.skip

最佳答案

一个更直接的解决方案是使用 pytest.importorskip相反。

关于python - PyTest:跳过整个模块/文件(python 2 和 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42511879/

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