-1
我想從另一個模塊來測試一個類中的每個方法。所以這裏是班級。如何在Python中從類外測試類方法?
#newmodule
class test:
def atest(a,b):
return a
def btest(a,b):
return b
和其他模塊中,我試圖做的事:
import unittest
import newmodule
test.atest(5,4).assert not errors
test.atest(7,9).assert not errors
注:我敢肯定有錯誤的種種這裏,但我只是嘲笑這件事作爲一個例子。我在這裏的主要問題是如何成功導入newmodule並測試每個方法。我懷疑,嘗試從課外測試方法,而不是僅僅測試函數,會有複雜性。
我已經失敗了蝙蝠的權利,因爲我越來越:
ImportError: no module named newmodule
即使他們是在同一個目錄。
我該如何成功導入這個模塊,如果是這樣,我能夠從課堂外測試方法嗎?
它應該命名爲'newmodule.py',而不是'newmodule'。另外,方法應該採用'self'參數,擁有'@ classmethod'並採用'cls'參數,或者擁有'@ staticmethod'裝飾器。 – zondo