在PyCharm中,我設置了py.test
作爲默認測試運行器。PyCharm + cProfile + py.test - > pstat快照視圖+調用圖爲空
我有一個簡單的測試案例:
import unittest
import time
def my_function():
time.sleep(0.42)
class MyTestCase(unittest.TestCase):
def test_something(self):
my_function()
現在我運行通過右鍵單擊該文件,並選擇Profile 'py.test in test_profile.py'
測試。
我看到測試在控制檯上成功運行(它說collected 1 items
)。但是,顯示生成的pstat文件的Statistics/Call Graph
視圖爲空,並且表示Nothing to show
。
我期望看到test_something
和my_function
的分析信息。我究竟做錯了什麼?
編輯1: 如果我更改文件名來一些東西,確實不開始與test_
,取出unittest.TestCase
並插入一個__main__
方法調用my_function
,我終於可以運行CPROFILE沒有py.test和我看到結果。
但是,我正在進行大量的測試工作。我想直接描述這些測試,而不是編寫額外的性能分析腳本。有沒有辦法調用py.test
測試發現模塊,以便我可以遞歸地檢索項目的所有測試? (unittest
發現是不夠的,因爲我們在發生器功能中產生了很多參數化測試,而unittest
未識別這些測試)。這樣我至少可以解決這個問題,只有一個額外的腳本。