How to support both old and new path / fspath ? #10261
-
I help maintain a pytest plugin, and I see there is a deprecation of the
Is there any way to fix the deprecation warning without dropping support for pytest < 7.0.0 ? Or is this forced? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Unfortunately at the moment there is no simple solution for that. If you need to support old pytest versions and do not want to see the warning, I guess one workaround is to declare different hooks depending on the pytest version: def collect_file_hook(file_path: Path, parent: Collector) -> Collector:
# The actual implementation goes here.
...
# Declare the hook depending on pytest's version.
version_tuple = getattr(pytest, "version_tuple", None)
if version_tuple and version_tuple[0] >= 7:
# Modern version.
def pytest_collect_file(file_path: Path, parent: Collector) -> Collector:
return collect_file_hook(file_path, parent)
else:
# Backward compatibility version.
def pytest_collect_file(path: py.path.local, parent: Collector) -> Collector:
return collect_file_hook(Path(file_path), parent) Definitely less than ideal, but that is what I can come up with for the moment. |
Beta Was this translation helpful? Give feedback.
Unfortunately at the moment there is no simple solution for that.
If you need to support old pytest versions and do not want to see the warning, I guess one workaround is to declare different hooks depending on the pytest version: