|
63 | 63 | ALL_IMAGE_FORMATS = RASTER_IMAGE_FORMATS + VECTOR_IMAGE_FORMATS |
64 | 64 |
|
65 | 65 |
|
| 66 | +def _get_item_dir(item): |
| 67 | + # .path is available starting from pytest 7, .fspath is for older versions. |
| 68 | + return getattr(item, "path", Path(item.fspath)).parent |
| 69 | + |
| 70 | + |
66 | 71 | def _hash_file(in_stream): |
67 | 72 | """ |
68 | 73 | Hashes an already opened file. |
@@ -445,19 +450,19 @@ def get_baseline_directory(self, item): |
445 | 450 | baseline_dir = compare.kwargs.get('baseline_dir', None) |
446 | 451 | if baseline_dir is None: |
447 | 452 | if self.baseline_dir is None: |
448 | | - baseline_dir = Path(item.fspath).parent / 'baseline' |
| 453 | + baseline_dir = _get_item_dir(item) / 'baseline' |
449 | 454 | else: |
450 | 455 | if self.baseline_relative_dir: |
451 | 456 | # baseline dir is relative to the current test |
452 | | - baseline_dir = Path(item.fspath).parent / self.baseline_relative_dir |
| 457 | + baseline_dir = _get_item_dir(item) / self.baseline_relative_dir |
453 | 458 | else: |
454 | 459 | # baseline dir is relative to where pytest was run |
455 | 460 | baseline_dir = self.baseline_dir |
456 | 461 |
|
457 | 462 | baseline_remote = (isinstance(baseline_dir, str) and # noqa |
458 | 463 | baseline_dir.startswith(('http://', 'https://'))) |
459 | 464 | if not baseline_remote: |
460 | | - return Path(item.fspath).parent / baseline_dir |
| 465 | + return _get_item_dir(item) / baseline_dir |
461 | 466 |
|
462 | 467 | return baseline_dir |
463 | 468 |
|
@@ -686,7 +691,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None): |
686 | 691 | hash_library_filename = compare.kwargs.get("hash_library", None) or self.hash_library |
687 | 692 | if self._hash_library_from_cli: # for backwards compatibility |
688 | 693 | hash_library_filename = self.hash_library |
689 | | - hash_library_filename = (Path(item.fspath).parent / hash_library_filename).absolute() |
| 694 | + hash_library_filename = _get_item_dir(item) / hash_library_filename |
690 | 695 |
|
691 | 696 | if not Path(hash_library_filename).exists(): |
692 | 697 | pytest.fail(f"Can't find hash library at path {hash_library_filename}") |
|
0 commit comments