@songying
2018-11-20T02:19:04.000000Z
字数 1243
阅读 1236
pytest
pytest -rxXs# show extra info on xfailed, xpassed, and skipped tests
@pytest.mark.skip(reason="no way of currently testing this")def test_the_unknown():...
pytest.skip()函数
def test_function():if not valid_config():pytest.skip("unsupported configuration")
pytest.skip(reason,allow_module_level=True)
import pytestif not pytest.config.getoption("--custom-flag"):pytest.skip("--custom-flag is missing, skipping tests", allow_module_level=True)
在某些条件下才进行skip, 那么则使用skipif
import sys@pytest.mark.skipif(sys.version_info < (3,6), reason="requires python3.6 or higher")def test_function():...
如果条件为真, 则该test function将会被skip。
import mymoduleminversion = pytest.mark.skipif(mymodule.__versioninfo__ < (1,1), reason="at least mymodule-1.1 required")@minversiondef test_function():...
# test_myothermodule.pyfrom test_mymodule import minversion@minversiondef test_anotherfunction():...
@pytest.mark.skipif(sys.platform == 'win32', reason="does not run on windows")class TestPosixCalls(object):def test_function(self):"will not be setup or run under 'win32' platform"
如果条件为真, the marker 将跳过该class中的所有test 方法
