pytest parametrize 我缺少必需的位置参数

sus*_*nne 11 python pytest

我尝试为我的单元测试添加 use pytest parametrize 。但我看到“缺少必需的位置参数”的错误。您能帮忙看看问题出在哪里吗?谢谢。

 @pytest.mark.parametrize("param", ["a", "b"])
    def test_pytest(self, param):
        print(param)
        assert False
Run Code Online (Sandbox Code Playgroud)

我得到以下异常:

class Tests(unittest.TestCase):
@contextlib.contextmanager
def testPartExecutor(self, test_case, isTest=False):
    old_success = self.success
    self.success = True
    try:
>       yield

           with outcome.testPartExecutor(self):
                self.setUp()
            if outcome.success:
                outcome.expecting_failure = expecting_failure
                with outcome.testPartExecutor(self, isTest=True):
>                   testMethod()
E                   TypeError: test_pytest() missing 1 required positional argument: 'param'
Run Code Online (Sandbox Code Playgroud)

jav*_*dba 0

我有同样的问题。看起来parametrize并不总是在测试类中工作,但确实在独立函数上工作。