Skip to content

Commit

Permalink
add hook to the pytest vscode plugin to determine how many xdist work…
Browse files Browse the repository at this point in the history
…ers to use based on how many tests are selected
  • Loading branch information
DetachHead authored Jun 2, 2024
1 parent 6d88415 commit d8d9a0d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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 Any, Dict, Generator, List, Optional, Union, TypedDict, Literal # noqa: E402


class TestData(TypedDict):
Expand Down Expand Up @@ -881,3 +881,12 @@ 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,
)


@pytest.hookimpl(hookwrapper=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"""
num_workers = (yield).get_result()
if "vscode_pytest" in config.option.plugins:
return min(num_workers, len(config.option.file_or_dir))
return num_workers

0 comments on commit d8d9a0d

Please sign in to comment.