我运行py.test用夹具在conftest文件.你可以看到下面的代码(一切正常):
example_test.py
import pytest
@pytest.fixture
def platform():
return "ios"
@pytest.mark.skipif("platform == 'ios'")
def test_ios(platform):
if platform != 'ios':
raise Exception('not ios')
def test_android_external(platform_external):
if platform_external != 'android':
raise Exception('not android')
Run Code Online (Sandbox Code Playgroud)
conftest.py
import pytest
@pytest.fixture
def platform_external():
return "android"
Run Code Online (Sandbox Code Playgroud)
现在我希望能够跳过一些不适用于我当前测试运行的测试.在我的例子中,我正在为iOS或Android运行测试(这仅用于演示目的,可以是任何其他表达式).
不幸的是,我无法在声明中得到(我的外部定义夹具).当我运行下面的代码时,我收到以下异常:.我不知道这是否是py.test错误,因为本地定义的灯具正在工作.platform_externalskipifNameError: name 'platform_external' is not defined
example_test.py的附加组件
@pytest.mark.skipif("platform_external == 'android'")
def test_android(platform_external):
"""This test will fail as …Run Code Online (Sandbox Code Playgroud) 我有一个长期测试,持续2天,我不想包括在通常的测试运行中.我也不想输入命令行参数,这会在每次通常的测试运行中取消选择它和其他测试.当我真正需要时,我宁愿选择默认取消选择的测试.我尝试将测试重命名test_longrun为longrun并使用该命令
py.test mytests.py::longrun
Run Code Online (Sandbox Code Playgroud)
但这不起作用.