Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add backwards compatibility for pytest hook wrapper #23781

Merged
merged 12 commits into from
Jul 15, 2024
17 changes: 14 additions & 3 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import pathlib
import sys
import traceback


import pluggy
import pytest

script_dir = pathlib.Path(__file__).parent.parent
Expand Down Expand Up @@ -892,8 +891,20 @@ def send_post_request(
)


def pluggy_version():
return pluggy.__version__


def compat_hookimpl(*args, **kwargs):
if pluggy_version() >= "1.1.0":
kwargs["wrapper"] = kwargs.pop("hookwrapper", False)
else:
kwargs["hookwrapper"] = kwargs.pop("wrapper", False)
eleanorjboyd marked this conversation as resolved.
Show resolved Hide resolved
return pluggy.HookimplMarker("pytest")(*args, **kwargs)


class DeferPlugin:
@pytest.hookimpl(wrapper=True)
@compat_hookimpl(wrapper=True)
def pytest_xdist_auto_num_workers(self, config: pytest.Config) -> Generator[None, int, int]:
"""determine how many workers to use based on how many tests were selected in the test explorer"""
return min((yield), len(config.option.file_or_dir))
eleanorjboyd marked this conversation as resolved.
Show resolved Hide resolved
Expand Down