我在 pytest 中遇到了一个非常神秘的错误,在添加了“@pytest.mark.parametrize”装饰器之后,测试开始抛出以下错误:
ValueError: <function ... at ...> uses no argument 'parameters'
Run Code Online (Sandbox Code Playgroud)
我在这里找到了错误的来源
这是我的函数签名的样子(简化):
@patch('dog')
@pytest.mark.parametrize('foo,bar', test_data)
def test_update_activity_details_trainer_and_gear(self, foo, bar, dog):
Run Code Online (Sandbox Code Playgroud)
事实证明 pytest 中装饰器的顺序很重要
@pytest.mark.parametrize('foo,bar', test_data)
@patch('dog')
def test_update_activity_details_trainer_and_gear(self, dog, foo, bar):
Run Code Online (Sandbox Code Playgroud)
更改顺序消除了错误