pytest 2.3 adding teardowns within the class

前端 未结 2 1938
小蘑菇
小蘑菇 2021-01-15 20:43

I\'m researching new version of pytest (2.3) and getting very excited about the new functionality where you

\"can precisely control teardown by regis

2条回答
  •  时光说笑
    2021-01-15 21:49

    Indeed, there are no good examples for teardown yet. The request object has a addfinalizer method. Here is an example usage:

    @pytest.setup(scope=...)
    def mysetup(request):
         ...
         request.addfinalizer(finalizerfunction)
         ...
    

    The finalizerfunction will be called when all tests withing the scope finished execution.

提交回复
热议问题