2013-04-12 65 views
0

爲什麼外層循環只執行最後一次迭代?爲什麼我的循環沒有迭代?

class LanguageSpecificTest(unittest.TestCase): 

    # Body omitted 

for style in [ "inline", "inline_scripted", 
       "external", "external_scripted", 
       "internal", "internal_scripted", 
      ]: 
    print style 

    for language, text_id, direction, text, check_text in (
       ("french", "reply_1", "с французского", "жизнь", "В большом дворце, в Ферраре, в один зимний вечер"), 
      ): 

     test_name = 'test_translation_test_phrases_for_%s_pages' % language 
     def my_test_generator(language, text_id, check_text): 
      def ubergenerator(self): 
       ##### 
      return ubergenerator 
     t = my_test_generator(language, text_id, check_text) 
     t.__name__ = test_name 
     setattr(LanguageSpecificTest, test_name, t) 

當我啓動測試中,它打印:

inline 
inline_scripted 
external 
external_scripted 
internal 
internal_scripted 
http://127.0.0.1:5000/translate?lang=french&style=internal_scripted 

,去只有通過一個測試,不是6。爲什麼我看不到

http://127.0.0.1:5000/translate?lang=french&style=inline 
http://127.0.0.1:5000/translate?lang=french&style=inline_scripted 
http://127.0.0.1:5000/translate?lang=french&style=external 
http://127.0.0.1:5000/translate?lang=french&style=external_scripted 
http://127.0.0.1:5000/translate?lang=french&style=internal 
http://127.0.0.1:5000/translate?lang=french&style=internal_scripted 

哦天啊,救我星期五晚上。

+0

你爲什麼不告訴我們我們可以實際運行的東西? – NPE

+0

你是否嘗試過使用調試器? – Alkini

回答

3
test_name = 'test_translation_test_phrases_for_%s_pages' % language 
    setattr(LanguageSpecificTest, test_name, t) 

你只在test_name使用language,所以當你去不同的style是你覆蓋相同的屬性。

+0

你說得對。此外,我必須將'style'作爲參數傳遞給'my_test_generator'。 – Nakilon

相關問題