好的,我通过在整个“会话”范围内使用funcarg来使其工作
finalizer:
@pytest.fixture(scope = "session")def finalizer(): return Finalizer()class Finalizer(object): def __init__(self): self.fin_funcs = [] def add_fin_func(self, func): self.fin_funcs.append(func) def remove_fin_func(self, func): try: self.fin_funcs.remove(func) except: pass def execute(self): for func in reversed(self.fin_funcs): func() self.fin_funcs = []class TestSomething(object): @classmethod @pytest.fixture(scope = "class", autouse = True) def setup(self, request, finalizer): self.finalizer = finalizer request.addfinalizer(self.finalizer.execute) self.finalizer.add_fin_func(lambda: some_teardown()) def test_with_teardown(self): #some test self.finalizer.add_fin_func(self.additional_teardown) def additional_teardown(self): #additional teardown
感谢@ hpk42答复电子邮件并帮助我获得最终版本。
注意:与xfailing其余步骤和改进的方案一起,这现在构成了一个很好的
Test-Step结构
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)