vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.21k stars 766 forks source link

Unit testing - mocking objects #658

Open m-kostrzewa opened 6 years ago

m-kostrzewa commented 6 years ago

Hello,

I want to unit test my code that uses pyvmomi. I don't want it have any side effects or for it to make any requests. I don't really want to use replay tests for testing my own code either.

I'm having a hard time coming up with a way to mock this API. I'm looking at SoapStubAdapter class wondering whether I can just mock its InvokeMethod to not do anything except return what I want.

Of course, this leads to many more problems. Is there a way to do this?

jeking3 commented 5 years ago

This is a great question - I would like to know the answer as well. My guess is a well-placed MagicMock would allow you to provide your own mocked objects. I suspect due to the generated nature of the code there's probably one method in VmomiSupport that instantiates all Managed Objects or Data Objects.