3

I have a method which I am unit testing

def some_functionality():
    must_call_first()
    must_call_second()

My current approach

@patch('module.must_call_first', autospec=True)
@patch('module.must_call_second', autospec=True)
def test_some_functionality(patch_second,patch_first):
     # execute    
     some_functionality()

     # assert
     patch_first.assert_called_once()
     patch_second.assert_called_once()

Issue:

  • The sequence of method-call for must_call_first and must_call_second will not be tested with my test case.
  • If I change the actual method and change the order, my test case would still pass. But ideally, it should not!

Is there a way I can make sure that the must_call_first method was called before must_call_second.?

Jay Joshi
  • 1,402
  • 1
  • 13
  • 32

0 Answers0