I have a function in main module which takes in two values and performs opertaions on them.This uses a global variable which is created before calling this function
def calc(keys,values):
if globalvar == "calc":
return sum(keys)
else:
return sum(values)
Now in unittesting
class Testcalc(TestCase):
@mock.patch('module.globalvar ', "calc")
def test_unit(self,calc):
keys=[1,2,3]
values=[4,5,6]
sum=module.calc(keys,values)
"""
check asserts
"""
I am getting an type error with invalid arguments.
TypeError('test_unit() takes exactly 2 arguments (1 given)',)
Could anyone show me the correct way of mocking the global variable
Update: This worked for me not sure why
class Testcalc(TestCase):
@mock.patch('module.globalvar')
def test_unit(self,var):
keys=[1,2,3]
values=[4,5,6]
var="calc"
sum=module.calc(keys,values)
"""
check asserts
"""
Thank you everyone
test_unit(), i.e. where you use it.