| 32 | |
| 33 | @pytest.fixture |
| 34 | def mock_comm(): |
| 35 | _widget_attrs['_comm_default'] = getattr(Widget, '_comm_default', undefined) |
| 36 | Widget._comm_default = lambda self: MockComm() |
| 37 | _widget_attrs['_ipython_display_'] = Widget._ipython_display_ |
| 38 | def raise_not_implemented(*args, **kwargs): |
| 39 | raise NotImplementedError() |
| 40 | Widget._ipython_display_ = raise_not_implemented |
| 41 | |
| 42 | yield MockComm() |
| 43 | |
| 44 | for attr, value in _widget_attrs.items(): |
| 45 | if value is undefined: |
| 46 | delattr(Widget, attr) |
| 47 | else: |
| 48 | setattr(Widget, attr, value) |