我正在嘗試創建一個單元測驗,當我嘗試使用另一個檔案中的函式時出現一些錯誤。您可以在下面看到我正在嘗試做的基本想法的示例。我是 Python 的初學者,所以我不確定是什么問題。
在檔案 1 中:model.py
Class Model(parameters):
def calc_maximum(self, data, thresholds):
df['Max']= ...
return df
def calc_model_output(self,data,param,param2):
S=self.calc_maximum(data,thresholds)
Si=S param2
return Si
在檔案 2 中:test.py
import model as ml
import unittest
...
...
class Tests(unittest.Testcase):
def test_calc_maximum(self):
Expected1=ml.Model.calc_maximum(self,input1, input2)
def test_calc_model_output(self):
Expected2=ml.Model.calc_model_output(self,input1,input2,input3)
當我嘗試運行 test.py 檔案時,測驗Expected1似乎作業正常,但我從Expected2行中收到以下錯誤:
AttributeError: 'Tests' object has no attribute 'calc_maximum.
有任何想法嗎?
uj5u.com熱心網友回復:
只需在Expected1中的Model后加括號,即使Expected1
Expected1=ml.Model().calc_maximum(input1,input2)
對 Expected2 做同樣的事情
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/464428.html
