(mock)
| 699 | |
| 700 | @contextmanager |
| 701 | def _mock_context(mock): |
| 702 | context = mock.return_value = Mock() |
| 703 | context.__enter__ = Mock() |
| 704 | context.__exit__ = Mock() |
| 705 | |
| 706 | def on_exit(*x): |
| 707 | if x[0]: |
| 708 | raise x[0] from x[1] |
| 709 | context.__exit__.side_effect = on_exit |
| 710 | context.__enter__.return_value = context |
| 711 | try: |
| 712 | yield context |
| 713 | finally: |
| 714 | context.reset() |
| 715 | |
| 716 | |
| 717 | @contextmanager |