我有参数化测试,这些测试从夹具中获取输入,如以下代码片段所示。这些灯具只能在与是否设置某个pytest标记有关的特定条件下工作。
我的问题:我如何在PytestConfig的定义中询问是否存在某个标记,以跳过PytestConfig内部的某些部分,我知道如果排除某个标记,该部分将会失败?
我想为pytest -m 'not markertobeskipped'
import os
import pytest
class PytestConfig:
# here I'd like to throw in some conditional logic along the lines of:
# "if pytest is called with 'not markertobeskipped': ...
missing_config = os.getenv('SOME_CONFIGURATION_NOT_PRESENT_IF_MARKERTOBESKIPPED', None)
# here, in reality some longish loading process would happen
assert missing_config
@staticmethod
def get_input_data():
return []
class TestClass:
@pytest.mark.markertobeskipped
@pytest.mark.parametrize('input', PytestConfig.get_input_data())
def test_should_be_skipped_without_error(self, input):
assert input