3 ms·
Can you elaborate on this? What is the correct way to test external services that may have side effects in Python?
by samcal 10y ago
Can you elaborate on this? What is the correct way to test external services that may have side effects in Python?
- bebop 10y agoI think maybe because there is no type checking in Python. This makes it more trivial to have objects that quack like a duck, without the need to explicitly create a class that conforms to an interface.
- LgWoodenBadger 10y agoFWIW, you don't do that with Mockito either, in Java land. Mockito will happily use the existing type definition of your dependency, provided that the class declaration is not final (i.e. can't be extended).
- raphw 10y agoThis is actually not a requirement anymore. Mockito 2 can mock final types and methods.
- dom0 10y agoWhen it comes to external dependencies there are mostly two ways this is dealt with: - Often there is a backend-like structure, and you got a dummy backend of sorts. Django's mail sending is a typical example of this: https://docs.djangoproject.com/en/1.10/topics/email/#in-memory-backend https://docs.djangoproject.com/en/1.10/topics/email/#in-memo... - Another commonly seen way is that there is a backend of sorts passed around and can be injected with little hassle from the tests. Often you'll see what boils down to a Mock, just written by hand, because it tends to be little hassle, and often results in quite clear testing code. Generating types on the fly using mocking and then doing somewhat awkward indirect assertions is by comparison a bit convoluted and less clear.
- samcal 10y agoAh, that's where I was confused. I would call both of those solutions mocks.