After:: with _collect_new_figures() as figs: some_code() the list *figs* contains the figures that have been created during the execution of ``some_code``, sorted by figure number.
()
| 77 | |
| 78 | @contextlib.contextmanager |
| 79 | def _collect_new_figures(): |
| 80 | """ |
| 81 | After:: |
| 82 | |
| 83 | with _collect_new_figures() as figs: |
| 84 | some_code() |
| 85 | |
| 86 | the list *figs* contains the figures that have been created during the |
| 87 | execution of ``some_code``, sorted by figure number. |
| 88 | """ |
| 89 | managers = _pylab_helpers.Gcf.figs |
| 90 | preexisting = [manager for manager in managers.values()] |
| 91 | new_figs = [] |
| 92 | try: |
| 93 | yield new_figs |
| 94 | finally: |
| 95 | new_managers = sorted([manager for manager in managers.values() |
| 96 | if manager not in preexisting], |
| 97 | key=lambda manager: manager.num) |
| 98 | new_figs[:] = [manager.canvas.figure for manager in new_managers] |
| 99 | |
| 100 | |
| 101 | def _raise_on_image_difference(expected, actual, tol): |