【发布时间】:2014-07-24 03:15:37
【问题描述】:
我非常喜欢 pytest 的一个特性是pytest.fixture,它允许依赖注入。例如,我可以让一个夹具将一个新的随机字符串 silly_string 注入到任何需要它的函数中:
conftest.py:
@pytest.fixture(scope='function')
def silly_string(request):
return ''.join(random.choice(string.ascii_lowercase) for _ in range(5))
test_strings.py
def test_string_length(self, silly_string)
assert len(silly_string) == 5
显然是人为的例子。
我不知道 Robot Framework 中有任何等效功能。目前,我使用关键字创建一个新变量,然后将该变量作为参数传递。自动注入参数就好了。
Robot Framework 中是否有类似执行依赖注入的机制?
【问题讨论】:
标签: robotframework pytest