|
41 | 41 | from urllib.request import urlopen
|
42 | 42 |
|
43 | 43 | import pytest
|
| 44 | +from packaging.version import Version |
44 | 45 |
|
45 | 46 | from pytest_mpl.summary.html import generate_summary_basic_html, generate_summary_html
|
46 | 47 |
|
|
63 | 64 | ALL_IMAGE_FORMATS = RASTER_IMAGE_FORMATS + VECTOR_IMAGE_FORMATS
|
64 | 65 |
|
65 | 66 |
|
| 67 | +def _get_item_dir(item): |
| 68 | + if Version(pytest.__version__) < Version("7.0.0"): |
| 69 | + path = Path(item.fspath) |
| 70 | + else: |
| 71 | + path = item.path |
| 72 | + return path.parent |
| 73 | + |
| 74 | + |
66 | 75 | def _hash_file(in_stream):
|
67 | 76 | """
|
68 | 77 | Hashes an already opened file.
|
@@ -445,19 +454,19 @@ def get_baseline_directory(self, item):
|
445 | 454 | baseline_dir = compare.kwargs.get('baseline_dir', None)
|
446 | 455 | if baseline_dir is None:
|
447 | 456 | if self.baseline_dir is None:
|
448 |
| - baseline_dir = Path(item.fspath).parent / 'baseline' |
| 457 | + baseline_dir = _get_item_dir(item) / 'baseline' |
449 | 458 | else:
|
450 | 459 | if self.baseline_relative_dir:
|
451 | 460 | # baseline dir is relative to the current test
|
452 |
| - baseline_dir = Path(item.fspath).parent / self.baseline_relative_dir |
| 461 | + baseline_dir = _get_item_dir(item) / self.baseline_relative_dir |
453 | 462 | else:
|
454 | 463 | # baseline dir is relative to where pytest was run
|
455 | 464 | baseline_dir = self.baseline_dir
|
456 | 465 |
|
457 | 466 | baseline_remote = (isinstance(baseline_dir, str) and # noqa
|
458 | 467 | baseline_dir.startswith(('http://', 'https://')))
|
459 | 468 | if not baseline_remote:
|
460 |
| - return Path(item.fspath).parent / baseline_dir |
| 469 | + return _get_item_dir(item) / baseline_dir |
461 | 470 |
|
462 | 471 | return baseline_dir
|
463 | 472 |
|
@@ -686,7 +695,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None):
|
686 | 695 | hash_library_filename = compare.kwargs.get("hash_library", None) or self.hash_library
|
687 | 696 | if self._hash_library_from_cli: # for backwards compatibility
|
688 | 697 | hash_library_filename = self.hash_library
|
689 |
| - hash_library_filename = (Path(item.fspath).parent / hash_library_filename).absolute() |
| 698 | + hash_library_filename = _get_item_dir(item) / hash_library_filename |
690 | 699 |
|
691 | 700 | if not Path(hash_library_filename).exists():
|
692 | 701 | pytest.fail(f"Can't find hash library at path {hash_library_filename}")
|
|
0 commit comments