mercredi 19 août 2015

Python Unit Testing: Want to Find Out How a Method Was Called Without Changing the Method

I'm writing a unit test in Python for something that looks like this:

def code_to_test(x):
  #gets an instance of MyClass
  #does some stuff...

  (x,y,z) = my_class_instance.some_method(a,b)

  #other stuff happens with x, y, and z that I don't care about

All I want to do is find out how some_method got called. I DON'T want to change the return value.

But when I:

with mock.patch.object(module.MyClass, 'some_method') as mock_method:
  code_to_test(7)

I get need more than 0 values to unpack because that method returns a tuple. So if I don't want to specify the return value, it assumes None?

Should I even be mocking some_method if I don't care about the return value? Is there some way to just find out if it was called? How can I write a test so that the stuff after the method invokation can run with correct values of x,y,z?

Aucun commentaire:

Enregistrer un commentaire