简体   繁体   English

如何在Pytest中参数化依赖项

[英]how to parametrize dependencies in Pytest

Let's say that there are two strings to test: "foo" and "bar", and for each string there is one ore more corresponding lists, eg for "foo" -> list1, list2, ... and for "bar" -> list3, list4, ... . 假设要测试两个字符串:“ foo”和“ bar”,并且每个字符串都有一个或多个相应的列表,例如,“ foo”-> list1,list2,...和“ bar”- > list3,list4,...。 How should the parametrize decorator be filled? 参数化装饰器应如何填充?

You would pass in the parameters as follows: 您将按以下方式传递参数:

@pytest.mark.parametrize("foo, bar", [
    (list1, list2),
    (list3, list4)])
def test_xxx():
    ...

You can use this code as an example. 您可以使用代码作为示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM