Skip to content

How to support both old and new path / fspath ? #10261

Answered by nicoddemus
vidartf asked this question in General
Discussion options

You must be logged in to vote

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 vers…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vidartf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants