【发布时间】:2017-02-28 14:51:25
【问题描述】:
如果导入不起作用,我想跳过整个测试:
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 中运行代码时,出现以下错误:
不允许在测试之外使用 pytest.skip。如果您尝试装饰测试函数,请改用 @pytest.mark.skip 或 @pytest.mark.skipif 装饰器。
如何编写适用于所有提到的环境的代码/测试?我已经尝试像这样重写 except 块,但它只适用于最新配置:
try:
pytest.skip()
except:
pytestmark = pytest.mark.skip
【问题讨论】: