I am writing python tests for the first time. I am trying to test a basic mock. I want to return some value that I want when I call the function, rather than a mock object.
Here is the code: In views:
def myfunction():
return "Actual data"
In test:
class TestBasic(unittest.TestCase):
@patch('trailblazer.views.myfunction')
def testMyFunction(self, val):
print(val)
val.return_value = "Test value"
print(val)
op = myfunction()
print(op)
output:
<MagicMock name='myfunction' id='4520521120'>
<MagicMock name='myfunction' id='4520521120'>
Actual data
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
PS: I don't have my methods in a class and I don't want to change that.