Skip to content

Commit d8d9a0d

Browse files
authored
add hook to the pytest vscode plugin to determine how many xdist workers to use based on how many tests are selected
1 parent 6d88415 commit d8d9a0d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
sys.path.append(os.fspath(script_dir / "lib" / "python"))
1717

1818
from testing_tools import socket_manager # noqa: E402
19-
from typing import Any, Dict, List, Optional, Union, TypedDict, Literal # noqa: E402
19+
from typing import Any, Dict, Generator, List, Optional, Union, TypedDict, Literal # noqa: E402
2020

2121

2222
class TestData(TypedDict):
@@ -881,3 +881,12 @@ def send_post_request(
881881
f"Plugin error, exception thrown while attempting to send data[vscode-pytest]: {error} \n[vscode-pytest] data: \n{data}\n",
882882
file=sys.stderr,
883883
)
884+
885+
886+
@pytest.hookimpl(hookwrapper=True)
887+
def pytest_xdist_auto_num_workers(config: pytest.Config) -> Generator[None, int, int]:
888+
"""determine how many workers to use based on how many tests were selected in the test explorer"""
889+
num_workers = (yield).get_result()
890+
if "vscode_pytest" in config.option.plugins:
891+
return min(num_workers, len(config.option.file_or_dir))
892+
return num_workers

0 commit comments

Comments
 (0)