pytestのセットアップとteardown_byseyOrd

pytestのセットアップとティアダウン

1)pytestは、独立したセットアップとティアダウンの2つのセットと、比較的無料のセットアップとティアダウンのペアを提供します

2)モジュールレベルと機能レベル

  モジュールレベル(setup_module / teardown_module)#モジュールの最初と最後から開始(クラス内ではない)

  関数レベル(setup_function / teardown_function)#関数のユースケースでのみ有効(クラスでは不可)

3)メソッドレベルとクラスレベル

  メソッドレベル(setup_method / teardown_method)#メソッドの最初と最後から開始(クラス内)

  クラスレベル(setup_class / teardown_class)#(クラス内の)クラスの前後に1回だけ実行

3)クラスの内部(セットアップ/ティアダウン)#メソッドを呼び出す前後に実行

セットアップとティアダウンの例

インポートpytest 


モジュール方式の
DEFのsetup_module():
     印刷" setup_module:test_module.pyモジュール全体が一回だけ実行" 

DEFのteardown_module():
     印刷" teardown_module:test_module.pyモジュール全体が一回だけ実行" 


DEFのsetup_function( ):
     印刷setup_function:各ユースケースの開始前に実行されます

DEFのteardown_function():
     印刷teardown_function:各実施例の終了後に実行される


例で使用される試験モジュールの1。
DEFのtest_one():
    印刷" 実行中のテストモジュールtest_one ---- " 

例2の試験モジュールの
DEFのtest_two():
     印刷" 実行中のテストモジュールtest_two ---- " 


#のテストクラスの
クラスのテストケース():
     DEFのsetup_class (self):
         print" setup_class:すべてのユースケースが実行される前" 

    def teardown_class(s​​elf):
         print" teardown_class:すべてのユースケースが実行された後" )
  def setup_method(self):
         print" setup_method:各ユースケースの開始前に実行される" 

    def teardown_method(self):
         print" teardown_method:used after the end of each use case " def setup(self):
         print" setup:execute before the start before each use case " def teardown(self): 
         print" ティアダウン:各ユースケースの終了後に実行されます" def test_three(self): 
         print" Executing test class ---- test_three " def test_four(self): 
         print" Executing test class ---- test_four "場合 __name__ == " __main__ " 
    pytest.main([ " -s "" test_module.py " ])                    

 

 

 

おすすめ

転載: www.cnblogs.com/seyOrd/p/12681746.html