2012-11-22 49 views
0

我有不同的python unitttest方法打包爲TestSuite,並且一個特定的測試方法看起來像例如如何從python中的測試方法中提取測試方法名稱

<input.MyTest testMethod=test_simple> 

它看起來這是一個類(這個東西的類型是input.MyTest),但有一個附加屬性(?)TestMethod的。

如何從屬性testMethod(或其他內容)中提取名稱test_simple

測試代碼(MyTest.py)

class MyTest(unittest.TestCase): 
    def test_simple(self): 
     pass 

套房代碼

from input import MyTest 
suite = test.TestSuite() 
suite.addTest(MyTest("test_simple")) 
print suite._tests[0] 
+1

顯示你的代碼,通過不顯示它,你讓這個問題更容易回答。 –

+0

我也想知道MyTest和MyClass的東西。請詳細說明! – Alfe

回答

0

從文檔的快速細讀,你可能要開始與test.id()

ID( )

返回st環確定具體的測試用例。 這通常是測試方法的全稱,包括模塊和 類名。

+0

是的,就是這樣。 – Alex

+0

@Alex下一次,通過首先查看文檔,您可能會解決您自己的問題。 –

+0

這要快得多;-) – Alex