使用pytest中的parametrize来处理多个参数

huangapple go评论58阅读模式
英文:

Using parametrize for multiple arguments in pytest

问题

有这样一个函数:

def underscore_concat(*args):
    return "_".join(filter(None, ([*args]))).upper()

如何使用pytest.mark.parametrize 正确地传递多个参数?

类似这样:

@pytest.mark.parametrize("a, result", [("underscore", "concat", "test", "UNDERSCORE_CONCAT_TEST")])
def test_underscore_concat(a, result):
    assert underscore_concat(a, result) == result
英文:

There is such a function:

def underscore_concat(*args):
    return "_".join(filter(None, ([*args]))).upper()

How to correctly pass multiple parameters using pytest.mark.parametrize?

Something like this:

@pytest.mark.parametrize("a, result", [(["underscore", "concat", "test"], "UNDERSCORE_CONCAT_TEST")])
def test_underscore_concat(a, result):
    assert underscore_concat(**a) == result

答案1

得分: 0

@pytest.mark.parametrize("a, result", [(["underscore", "concat", "test"], "UNDERSCORE_CONCAT_TEST")])
def test_underscore_concat(a, result):
assert underscore_concat(*a) == result

英文:
@pytest.mark.parametrize("a, result", [(["underscore", "concat", "test"], "UNDERSCORE_CONCAT_TEST")])
def test_underscore_concat(a, result):
    assert underscore_concat(*a) == result

huangapple
  • 本文由 发表于 2023年3月3日 18:42:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626033.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定