0
from flexmock import flexmock
class Addition:
    def add(self,num1,num2):
        return num1+num2

creating a mock

mock=Addition()
flexmock(mock)

mock.should_receive('add')

assert mock.add(1,2)==3

I have mocked the Addition class using flexmock. Now Suppose If I further want to make sure that add method only receive integer value. How do I write the test case for added requirement. Or am I following the totally wrong path ?

Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76

1 Answers1

0

Well it really depends right. You could change your original function to have an Exception and you can test for cases that cause that to arise or you could do something like this (I use pytest btw):

def test_add(num1, num2):
    with pytest.raises(TypeError):
        return num1 + num2

test_add(2, 'fizz') ---> PASSED

test_add(2, 2) ---> FAILED
Failed: DID NOT RAISE <type 'exceptions.TypeError'>
gold_cy
  • 13,648
  • 3
  • 23
  • 45