Returns a wrapper around self that is compatible with `mock.patch `. The `mock.patch ` function (included in the standard library `unittest.mock` package since Python 3.3, or in the third-party ``mock`` package for older vers
(self)
| 479 | callback() |
| 480 | |
| 481 | def mockable(self) -> "_Mockable": |
| 482 | """Returns a wrapper around self that is compatible with |
| 483 | `mock.patch <unittest.mock.patch>`. |
| 484 | |
| 485 | The `mock.patch <unittest.mock.patch>` function (included in |
| 486 | the standard library `unittest.mock` package since Python 3.3, |
| 487 | or in the third-party ``mock`` package for older versions of |
| 488 | Python) is incompatible with objects like ``options`` that |
| 489 | override ``__getattr__`` and ``__setattr__``. This function |
| 490 | returns an object that can be used with `mock.patch.object |
| 491 | <unittest.mock.patch.object>` to modify option values:: |
| 492 | |
| 493 | with mock.patch.object(options.mockable(), 'name', value): |
| 494 | assert options.name == value |
| 495 | """ |
| 496 | return _Mockable(self) |
| 497 | |
| 498 | |
| 499 | class _Mockable(object): |