I am learning how testing is done in Python using py.test . I am trying to check a specific situation, which is quite common when using other libraries, such as mock . In particular, testing that a function or method calls another called with the correct arguments. A return value is not required, just a confirmation that the tested method correctly calls.
Here is an example directly from docs :
>>> class ProductionClass: ... def method(self): ... self.something(1, 2, 3) ... def something(self, a, b, c): ... pass ... >>> real = ProductionClass() >>> real.something = MagicMock() >>> real.method() >>> real.something.assert_called_once_with(1, 2, 3)
Is it possible to do this with monkeypatch or fixtures from py.test without creating an efficient spelling of my own mocking class? I was looking for this specific use case but could not find an example. Does py.test an alternative way to implement such code?
source share