I'm trying to create a unit test and I'm having some errors when I try to use a function from another file. You can see an example of the basic idea of what I am trying to do below. I am a beginner in Python so I'm not sure what's the problem.
In file 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
in file 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)
when I try to run test.py file, the test for Expected1
seems to work ok, but I get the following error from theExpected2
row:
AttributeError: 'Tests' object has no attribute 'calc_maximum
.
Any ideas?
CodePudding user response:
Just add brackets after Model in Expected1, i.e. make Expected1
Expected1=ml.Model().calc_maximum(input1,input2)
Do the same for Expected2