| 152 | return expected_fname |
| 153 | |
| 154 | def compare(self, fig, baseline, extension, *, _lock=False): |
| 155 | __tracebackhide__ = True |
| 156 | |
| 157 | if self.remove_text: |
| 158 | remove_ticks_and_titles(fig) |
| 159 | |
| 160 | actual_path = (self.result_dir / baseline).with_suffix(f'.{extension}') |
| 161 | kwargs = self.savefig_kwargs.copy() |
| 162 | if extension == 'pdf': |
| 163 | kwargs.setdefault('metadata', |
| 164 | {'Creator': None, 'Producer': None, |
| 165 | 'CreationDate': None}) |
| 166 | |
| 167 | lock = (cbook._lock_path(actual_path) |
| 168 | if _lock else contextlib.nullcontext()) |
| 169 | with lock: |
| 170 | try: |
| 171 | fig.savefig(actual_path, **kwargs) |
| 172 | finally: |
| 173 | # Matplotlib has an autouse fixture to close figures, but this |
| 174 | # makes things more convenient for third-party users. |
| 175 | plt.close(fig) |
| 176 | expected_path = self.copy_baseline(baseline, extension) |
| 177 | _raise_on_image_difference(expected_path, actual_path, self.tol) |
| 178 | |
| 179 | |
| 180 | def _pytest_image_comparison(baseline_images, extensions, tol, |