我從stack_overflow_entry瞭解到,在Python裝飾器中,它們按照它們出現在源代碼中的順序進行應用。根據之前的裝飾器結果,python裝飾器可以被執行還是跳過?
那麼下面的代碼片段應該如何表現呢?
@unittest.skip("Something no longer supported")
@skipIf(not something_feature_enabled, "Requires extra crunchy cookies to run")
def test_this():
....
第一裝飾(下面說明)請求測試運行到完全跳過test_this()
@unittest.skip("Something no longer supported")
雖然第二裝飾詢問測試運行跳過運行test_this()
有條件。
@skipIf(not something_feature_enabled, "Requires extra crunchy cookies to run")
那麼這是否意味着test_this
將不會運行在所有除非我們首先把條件跳轉裝飾?
此外,是否有任何方式在Python中定義相關的裝飾器執行?例如
@skipIf("Something goes wrong")
@skipIf(not something_feature_enabled, "Requires extra crunchy cookies to run")
@log
@send_email
def test_this():
....
的想法是使@log
執行和@send_email
如果是true
。
道歉,如果我失去了一些非常明顯的東西。
感謝@abarnert對此進行了詳細說明。 – splintercell 2014-11-05 21:41:21