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 hook to vscode_pytest to determine number xdist workers to use based on count of selected tests #23539

Merged
merged 9 commits into from
Jun 20, 2024
24 changes: 22 additions & 2 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
script_dir = pathlib.Path(__file__).parent.parent
sys.path.append(os.fspath(script_dir))
sys.path.append(os.fspath(script_dir / "lib" / "python"))

from testing_tools import socket_manager # noqa: E402
from typing import Any, Dict, List, Optional, Union, TypedDict, Literal # noqa: E402
from typing import ( # noqa: E402
Any,
Dict,
List,
Optional,
Union,
TypedDict,
Literal,
Generator,
)


class TestData(TypedDict):
Expand Down Expand Up @@ -882,3 +890,15 @@ def send_post_request(
f"Plugin error, exception thrown while attempting to send data[vscode-pytest]: {error} \n[vscode-pytest] data: \n{data}\n",
file=sys.stderr,
)


try:
import xdist # pyright: ignore[reportMissingImports] # noqa: F401
except ModuleNotFoundError:
pass
else:

@pytest.hookimpl(wrapper=True)
def pytest_xdist_auto_num_workers(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))
Loading