我已经参数化了测试,这些测试从fixture中获取输入,如下面的代码片段所示。这些固定装置只能在特定的条件下工作,这些条件与是否设置了特定的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
目前没有回答
相关问题 更多 >
编程相关推荐