我正在使用pytest的参数化注释将params传递给一个类.我能够在测试方法中使用参数,但是,我无法弄清楚如何在setup_class方法中使用这些参数.
import pytest
params = ['A','B','C']
@pytest.mark.parametrize('n', params)
class TestFoo:
def setup_class(cls):
print ("setup class:TestFoo")
# Do some setup based on param
def test_something(self, n):
assert n != 'D'
def test_something_else(self, n):
assert n != 'D'
我尝试添加’n’作为参数,如测试方法,如下所示:
def setup_class(cls, n):
print ("setup class:TestFoo")
# Do some setup based on param
这会导致错误:
self =
def setup(self):
setup_class = xunitsetup(self.obj, 'setup_class')
if setup_class is not None:
setup_class = getattr(setup_class, 'im_func', setup_class)
setup_class = getattr(setup_class, '__func__', setup_class)
> setup_class(self.obj)
E TypeError: setup_class() takes exactly 2 arguments (1 given)
是否有其他方法在setup_class方法中使用该参数?